<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zach Gollwitzer</title>
    <description>The latest articles on DEV Community by Zach Gollwitzer (@zachgoll).</description>
    <link>https://dev.to/zachgoll</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%2F338883%2F8442d89a-a05e-459c-b174-cb1b3139a08a.png</url>
      <title>DEV Community: Zach Gollwitzer</title>
      <link>https://dev.to/zachgoll</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zachgoll"/>
    <language>en</language>
    <item>
      <title>CSS Grid Course for Complete Beginners</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Mon, 24 May 2021 10:14:34 +0000</pubDate>
      <link>https://dev.to/zachgoll/css-grid-course-for-complete-beginners-4256</link>
      <guid>https://dev.to/zachgoll/css-grid-course-for-complete-beginners-4256</guid>
      <description>&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/7-html-crash-course/" rel="noopener noreferrer"&gt;A basic understanding of HTML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/8-css-crash-course/" rel="noopener noreferrer"&gt;A basic understanding of CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/10-flexbox-crash-course/" rel="noopener noreferrer"&gt;A working knowledge of Flexbox&lt;/a&gt; (I will be borrowing many concepts from my Flexbox tutorial here)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://youtu.be/46Dh-VtBja4" rel="noopener noreferrer"&gt;View this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By the end of this lesson, you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be able to explain to someone what CSS Grid is&lt;/li&gt;
&lt;li&gt;Understand the basic syntax and model of CSS Grid&lt;/li&gt;
&lt;li&gt;Understand how CSS Grid and Flexbox (prior lesson) relates&lt;/li&gt;
&lt;li&gt;Understand when to use Flexbox and when to use CSS Grid for CSS layouts (yes, they can be used together!)&lt;/li&gt;
&lt;li&gt;Be able to build the &lt;a href="https://en.wikipedia.org/wiki/Holy_grail_(web_design)" rel="noopener noreferrer"&gt;Holy Grail Layout&lt;/a&gt; with CSS Grid and Flexbox (see below)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014690356%2F3Fs96vRyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014690356%2F3Fs96vRyc.png" alt="holy-grail-2.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the "fullstackroadmap" series?
&lt;/h2&gt;

&lt;p&gt;This is part of my fullstack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first fullstack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/" rel="noopener noreferrer"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc" rel="noopener noreferrer"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series" rel="noopener noreferrer"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq" rel="noopener noreferrer"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/" rel="noopener noreferrer"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/" rel="noopener noreferrer"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev" rel="noopener noreferrer"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query" rel="noopener noreferrer"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Begin - What is CSS Grid?
&lt;/h2&gt;

&lt;p&gt;CSS Grid is a 2-dimensional layout system.  In other words, you can control how elements sit on both the x and y axis, which is an &lt;em&gt;addition&lt;/em&gt; to &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/10-flexbox-crash-course/" rel="noopener noreferrer"&gt;Flexbox&lt;/a&gt;, which we learned in the prior lesson of this series.&lt;/p&gt;

&lt;p&gt;Here is why we need CSS Grid in our lives:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Before 2009 (pre Flexbox/Grid) front-end developers used "hacky" solutions to create complex layouts.  This included those nasty &lt;code&gt;float&lt;/code&gt; and &lt;code&gt;clear&lt;/code&gt; properties along with some tedious mathematical calculations.&lt;/li&gt;
&lt;li&gt;From 2009-2017 (Flexbox exists, Grid doesn't), the CSS layout game was easier than before, but still didn't have a great solution for "high level" layouts (such as the &lt;a href="https://en.wikipedia.org/wiki/Holy_grail_(web_design)" rel="noopener noreferrer"&gt;Holy Grail layout&lt;/a&gt;).  You could get it done with Flexbox, but this required some "tricks" and a good amount of ingenuity.&lt;/li&gt;
&lt;li&gt;From 2017 forward, we have CSS Grid for high-level, complex, 2-d layouts and Flexbox for simpler layouts.  It's the best of both worlds.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But the next obvious question becomes... How do we know when to use CSS Grid vs. Flexbox?&lt;/p&gt;

&lt;h3&gt;
  
  
  When to use CSS Grid vs. Flexbox
&lt;/h3&gt;

&lt;p&gt;CSS Grid and Flexbox work together.  They are both part of the CSS3 spec, and while they do similar things related to layouts, they were not intended to compete with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Grid when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need full control of rows AND columns (examples: full page layouts, gallery items)&lt;/li&gt;
&lt;li&gt;You want to explicitly define the layout regardless of content size (i.e. if you are using Flexbox and it starts to get really complicated with a bunch of heights and widths, you probably should be using Grid)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Flexbox when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your content is a row OR column (examples: horizontal navbar, vertical sidebar)&lt;/li&gt;
&lt;li&gt;You want the size of items to determine layout&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will go through an example of this later in the tutorial so you can see this in action.&lt;/p&gt;

&lt;p&gt;One more thing before we get started...&lt;/p&gt;

&lt;h3&gt;
  
  
  Do all browsers support CSS Grid?
&lt;/h3&gt;

&lt;p&gt;For the sake of a beginner learning front-end web development, YES.  As of March 2017, all major browsers have built-in support for CSS Grid, and you shouldn't be worried about this.&lt;/p&gt;

&lt;p&gt;For someone working in the industry who must support Internet Explorer (bless your soul) and some other old browsers, NO.  You will need "fallback" styles.  Luckily, with media queries, this is straightforward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@supports&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Put your CSS Grid styles here */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything you put in that block will apply if the browser supports CSS Grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid Container vs. Grid Items
&lt;/h2&gt;

&lt;p&gt;If this heading sounds familiar, good.  If not, &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/10-flexbox-crash-course/" rel="noopener noreferrer"&gt;please please please go read my Flexbox tutorial&lt;/a&gt; before continuing forward.  This post is highly dependent on concepts we learned there and I will be glossing over them here.&lt;/p&gt;

&lt;p&gt;Just like we had "Flex containers" and "Flex Items", with CSS Grid, we have "Grid Containers" and "Grid Items".&lt;/p&gt;

&lt;p&gt;Look at the following HTML and CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like Flexbox, we activate CSS Grid by setting the &lt;code&gt;display&lt;/code&gt; CSS property. &lt;/p&gt;

&lt;p&gt;With a few tweaks to the grid settings and some additional color styles on the grid items, you can create something that looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014484678%2Fm4ZpE2THG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014484678%2Fm4ZpE2THG.png" alt="grid-container.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a preview to the remainder of the tutorial, notice the following things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The above visual is one of many examples I could have used.  For our example, I kept things simple and made our grid perfectly square (3 rows, 3 columns, all equal height and width)&lt;/li&gt;
&lt;li&gt;The dotted lines are important.  These are the boundaries for our grid.&lt;/li&gt;
&lt;li&gt;With CSS Grid, we call the rows and columns "tracks"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding CSS Grid is all about knowing how to manipulate the size and location of each grid item.  To do that, we have several container-level properties and several grid-item-level properties available.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you freak out
&lt;/h2&gt;

&lt;p&gt;What you're about to see is a long list of CSS properties that we can use with CSS Grid.  At first glance, they are intimidating, but if you went through my &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/10-flexbox-crash-course/" rel="noopener noreferrer"&gt;Flexbox tutorial&lt;/a&gt;, you have the foundation required to understand this stuff well.  We will add some new concepts, but most of the content to follow is "layers" on top of what you already know.  I'm confident that the overwhelm you're about to feel will subside quickly as we dive in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid Container vs. Grid Item Properties
&lt;/h2&gt;

&lt;p&gt;Consistent with my prior tutorial on Flexbox, here are two cheat-sheets for CSS Grid that have really helped me.  When I was learning, I kept them open constantly.  I recommend you do the same for a couple weeks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://yoksel.github.io/grid-cheatsheet" rel="noopener noreferrer"&gt;Cheat Sheet #1&lt;/a&gt; - Great for experimenting with different property values in a live setting&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://grid.malven.co/" rel="noopener noreferrer"&gt;Cheat Sheet #2&lt;/a&gt; - Great for visualizing properties based on their container vs. item classification (as I've done below)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Also consistent with previous tutorials, below are links to the MDN documentation for CSS Grid properties. &lt;strong&gt;I will explain each of these in detail throughout the post.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Grid Container Properties
&lt;/h3&gt;

&lt;p&gt;Set these properties on the HTML "container" you want to turn into a grid.  Don't memorize these; we'll learn how they work later.&lt;/p&gt;

&lt;h4&gt;
  
  
  Activate the Grid
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/display" rel="noopener noreferrer"&gt;display: grid&lt;/a&gt; - Activates CSS Grid system on your HTML elements (other valid values include &lt;code&gt;inline-grid&lt;/code&gt; and &lt;code&gt;subgrid&lt;/code&gt;, but we won't cover these here)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Sizing
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-rows" rel="noopener noreferrer"&gt;grid-template-rows&lt;/a&gt; - Defines the size of the grid rows&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns" rel="noopener noreferrer"&gt;grid-template-columns&lt;/a&gt; - Defines the size of the grid columns&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap" rel="noopener noreferrer"&gt;row-gap&lt;/a&gt; - Defines the size of the horizontal "gutters" between rows&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap" rel="noopener noreferrer"&gt;column-gap&lt;/a&gt; - Defines the size of the vertical "gutters" between columns&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-rows" rel="noopener noreferrer"&gt;grid-auto-rows&lt;/a&gt; - When you don't explicitly set a row's size (via &lt;code&gt;grid-template-rows&lt;/code&gt;), the size is determined by this value.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-columns" rel="noopener noreferrer"&gt;grid-auto-columns&lt;/a&gt; - When you don't explicitly set a column's size (via &lt;code&gt;grid-template-columns&lt;/code&gt;), the size is determined by this value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alignment
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-flow" rel="noopener noreferrer"&gt;grid-auto-flow&lt;/a&gt; - Sets the algorithm used to place grid items that you don't explicitly place&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas" rel="noopener noreferrer"&gt;grid-template-areas&lt;/a&gt; - A bit hard to explain this property without an example.  I will cover this later in the tutorial.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-items" rel="noopener noreferrer"&gt;justify-items&lt;/a&gt; - Aligns items along the horizontal axis &lt;em&gt;within&lt;/em&gt; their grid areas&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items" rel="noopener noreferrer"&gt;align-items&lt;/a&gt; - Aligns items along the vertical axis &lt;em&gt;within&lt;/em&gt; their grid areas&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content" rel="noopener noreferrer"&gt;justify-content&lt;/a&gt; - Aligns the grid item "group" along the horizontal axis (similar to how we used it in Flexbox where &lt;code&gt;flex-direction: row&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-content" rel="noopener noreferrer"&gt;align-content&lt;/a&gt; - Aligns the grid item "group" along the vertical axis (a bit different than how we used it with Flexbox)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Grid Item Properties
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Sizing
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-start" rel="noopener noreferrer"&gt;grid-row-start&lt;/a&gt; - For a given grid item, defines the vertical starting point&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-end" rel="noopener noreferrer"&gt;grid-row-end&lt;/a&gt; - For a given grid item, defines the vertical ending point&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start" rel="noopener noreferrer"&gt;grid-column-start&lt;/a&gt; - For a given grid item, defines the horizontal ending point&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-end" rel="noopener noreferrer"&gt;grid-column-end&lt;/a&gt; - For a given grid item, defines the horizontal ending point&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Alignment
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-self" rel="noopener noreferrer"&gt;justify-self&lt;/a&gt; - Aligns a single grid item on the horizontal axis&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-self" rel="noopener noreferrer"&gt;align-self&lt;/a&gt; - Aligns a single grid item on the vertical axis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a visual of all these properties in one spot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014841596%2FWafHipog-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014841596%2FWafHipog-.png" alt="css-grid-properties.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Shorthand Grid Properties
&lt;/h3&gt;

&lt;p&gt;Just like Flexbox, Grid has shorthand properties that combine some of the above properties together.  Remember this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Both rules below are equivalent. */&lt;/span&gt;
&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-grow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-shrink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-basis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Shorthand property for Flexbox!
     Equivalent to:

     flex: &amp;lt;flex-grow&amp;gt; &amp;lt;flex-shrink&amp;gt; &amp;lt;flex-basis&amp;gt; */&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do similar things with CSS Grid.  I do not recommend using these until you have become comfortable with the longhand properties above.  Nevertheless, here they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid" rel="noopener noreferrer"&gt;grid&lt;/a&gt; - The shorthand of all shorthand properties.  This defines pretty much everything at once (row, columns, areas, flow)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template" rel="noopener noreferrer"&gt;grid-template&lt;/a&gt; - Similar to &lt;code&gt;grid&lt;/code&gt;, but less comprehensive.  Defines the rows, columns, and areas of the grid.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gap" rel="noopener noreferrer"&gt;gap (grid-gap)&lt;/a&gt; - Defines all the "gutters" at once&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-area" rel="noopener noreferrer"&gt;grid-area&lt;/a&gt; - Defines the entire area of a grid item at once&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row" rel="noopener noreferrer"&gt;grid-row&lt;/a&gt; - A subset of &lt;code&gt;grid-area&lt;/code&gt;, this defines the row sizing of a grid item&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column" rel="noopener noreferrer"&gt;grid-column&lt;/a&gt; - A subset of &lt;code&gt;grid-area&lt;/code&gt;, this defines the column sizing of a grid item&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And if you need to see these visually like I do, here is a mind map to reference.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014875820%2F3ULLn7PHI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619014875820%2F3ULLn7PHI.png" alt="shorthand-css.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1: Constructing the Grid
&lt;/h2&gt;

&lt;p&gt;While I'm confident we can get through this topic without much confusion, it's going to require a methodical series of steps.  Read carefully and don't skip ahead.  This goes in a specific order.&lt;/p&gt;

&lt;p&gt;First off, let's construct the "playground" we are going to use to explore CSS Grid.  In the Codepen below, the only grid-related property I have set is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Grid itself is activated, but we haven't set any properties on it yet.  Please read through the CSS comments in the Codepen below and get yourself comfortable.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/xxgqyLK?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Visually speaking, here is what we are dealing with.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016385876%2FVmoiET-6O.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016385876%2FVmoiET-6O.png" alt="grid-container-v1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In "grid speak", here is what we have done.  Since all of these properties default to these values, you could delete everything below and achieve the same layout as above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stretch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;justify-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stretch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Grid Template
&lt;/h3&gt;

&lt;p&gt;There is a lot to unpack here.  Let's start with these two properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;grid-template-rows&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grid-template-columns&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These two properties alone will define our "gridlines", and ultimately, the structure of our "grid".&lt;/p&gt;

&lt;p&gt;If we don't set these properties explicitly, we get something called an "implicit grid", which will always be 1 column wide and the number of rows will be based on the number of grid items.  In our case, we had 1 column X 3 rows (because we had 3 grid items).&lt;/p&gt;

&lt;p&gt;To really see this in action, let's remove the grid items for a moment and look at examples.  We will start simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you see &lt;code&gt;fr&lt;/code&gt;, this means "fractional unit", and works identically to how our &lt;code&gt;flex-grow&lt;/code&gt; and &lt;code&gt;flex-shrink&lt;/code&gt; values did in our &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/10-flexbox-crash-course/" rel="noopener noreferrer"&gt;Flexbox tutorial&lt;/a&gt; (again, if you haven't please read it before moving on).&lt;/p&gt;

&lt;p&gt;In the example above, we have defined &lt;code&gt;grid-template-rows&lt;/code&gt; in 3 equal parts.  We have allocated 3 "fractional units" (1fr + 1fr + 1fr), so each row will receive 33.33% of the available grid space.  We defined &lt;code&gt;grid-template-columns&lt;/code&gt; in 2 parts, but they are not equal.  In total, we have allocated 3 fr units, but gave 2 of them to the first column and 1 to the second.  If each unit is equal to 33.33% (1/3), then the first column will be 66.66% wide and the second column will be 33.33% wide.  Here is the grid we just defined:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016418268%2FXfNn1CUw-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016418268%2FXfNn1CUw-.png" alt="grid-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One thing that you'll notice is that we have 2 columns, but 3 "lines" that represent boundaries.  This is similar to the &lt;a href="https://betterexplained.com/articles/learning-how-to-count-avoiding-the-fencepost-problem/" rel="noopener noreferrer"&gt;fence-post math problem&lt;/a&gt;.  Because of this, I have renamed them to &lt;code&gt;CL-n&lt;/code&gt; and &lt;code&gt;RL-n&lt;/code&gt;, short for "Column Line #n" and "Row Line #n".&lt;/p&gt;

&lt;p&gt;Here's one more example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have defined 8 rows and 8 columns of equal width an height (i.e. a perfectly "square" grid).  Here is what it looks like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016595636%2Fc6eVlMb5f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016595636%2Fc6eVlMb5f.png" alt="grid-3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we move on, let's simplify our CSS by using the &lt;code&gt;repeat&lt;/code&gt; function.  In this tutorial, I won't be getting into the "shorthand" Grid properties much, but this one is simple and will save you some typing.  As opposed to typing a bunch of &lt;code&gt;1fr&lt;/code&gt; units to define our grid, we can write this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Positioning Items on the Grid
&lt;/h3&gt;

&lt;p&gt;Let's keep going with that 8x8 grid example from above and add some grid items.  By default, here is what we get when we add 3 grid items with no width/height and no additional Grid properties.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/YzNZRzQ?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In CSS Grid terminology, the "grid area" represents the space that a grid item occupies.  We have not explicitly instructed our grid to place the grid items, so they will take up 1 "cell" of the grid each.  Here is a more detailed visual:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016659374%2Fqj-KUfHfp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016659374%2Fqj-KUfHfp.png" alt="grid-4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above visual is the "default", but what if I wanted to place these three items in specific locations on the grid?  Maybe something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016667690%2F9FUU29K2o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016667690%2F9FUU29K2o.png" alt="grid-5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before CSS Grid, achieving this layout would require a tremendous effort.  With Grid, it's simple.  To place items, you just need to specify the "line" that they start/end on from a row/column perspective.  Let's break this down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grid item 1

&lt;ul&gt;
&lt;li&gt;Starts on RL-3, ends on RL-4&lt;/li&gt;
&lt;li&gt;Starts on CL-3, ends on CL-4&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Grid item 2

&lt;ul&gt;
&lt;li&gt;Starts on RL-6, ends on RL-7&lt;/li&gt;
&lt;li&gt;Starts on CL-6, ends on CL-7&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Grid item 3

&lt;ul&gt;
&lt;li&gt;Starts on RL-8, ends on RL-9&lt;/li&gt;
&lt;li&gt;Starts on CL-8, ends on CL-9&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let's take this information and translate it into CSS.  All of the properties below are grid item (not container) properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Optionally, you could could have used the &lt;code&gt;grid-row&lt;/code&gt; and &lt;code&gt;grid-column&lt;/code&gt; properties here to simplify, but like I mentioned earlier, it is best to use the longhand properties until you are really comfortable with CSS Grid!  Here's the result:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/poRPveN?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Sizing Items on the Grid
&lt;/h3&gt;

&lt;p&gt;By default, our grid items are filling the space of one grid "cell" naturally.  If you look at any of the Codepens above, you can see the following specs for our grid:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Grid container is 310px wide and 310px tall with a border of 5px.  Therefore, the total available space is 300px wide and 300px tall (when &lt;code&gt;box-sizing: border-box&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;The Grid is 8 x 8&lt;/li&gt;
&lt;li&gt;Each grid "cell" will be 37.5px wide and 37.5px tall (300px / 8)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two ways that we can resize them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set an explicit width and height on each&lt;/li&gt;
&lt;li&gt;Change the &lt;code&gt;grid-row-end&lt;/code&gt; and &lt;code&gt;grid-column-end&lt;/code&gt; properties&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Option #1 isn't great because it will open a can of worms we're not ready for yet.&lt;/p&gt;

&lt;p&gt;Let's try option #2 and replicate this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016706284%2FX_71rPxkY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016706284%2FX_71rPxkY.png" alt="grid-6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While this might seem difficult, we can use the same method we did to place the grid items above!  Here's the CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the result:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/JjENdJg?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Review: Setting up the Grid
&lt;/h3&gt;

&lt;p&gt;At this point, you know the basics of setting up a CSS Grid container and placing/sizing items within it.  The structure is relatively simple as you have seen throughout the tutorial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Generic CSS properties */&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#212226&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c"&gt;/* Grid container properties */&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this will get you started, there is more to talk about, and certainly some details that I purposefully omitted here.  We will circle back to some of these properties later.  For now, let's talk about aligning grid items within the grid container AND within their "grid areas".&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic CSS Grid Alignment
&lt;/h2&gt;

&lt;p&gt;If you following this tutorial closely, you might be asking why we are talking about "alignment".  Didn't we just talk about alignment?&lt;/p&gt;

&lt;p&gt;While we discussed the &lt;em&gt;placement&lt;/em&gt; and &lt;em&gt;sizing&lt;/em&gt; of grid items, we did not cover their alignment, which can happen in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Alignment within a item's "grid area"&lt;/li&gt;
&lt;li&gt;Alignment within a grid container&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  "Grid Area" Alignment
&lt;/h3&gt;

&lt;p&gt;We briefly covered what a "grid area" means, but not enough for you to walk away confidently.  Let's go back to our 8x8 grid and define a "grid area" that we want to experiment with.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016723160%2F8bzHtiScF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016723160%2F8bzHtiScF.png" alt="grid-7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since our grid is 8fr x 8fr, this "grid area" is 4fr x 4fr.  We can place a grid item in this space using the following HTML and CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#212226&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here it is live with some styling:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/wvgdaQy?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We know from earlier that the total size of a single grid "cell" is 37.5px wide and tall.  Therefore, our "grid area" here is 150px wide and tall (37.5 * 4), and our grid item is stretching to fit those dimensions.&lt;/p&gt;

&lt;p&gt;But what if we explicitly set some dimensions on our grid item?  Let's set this grid item to 120px:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;120px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;120px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we do this, our "grid area" will remain the same, but now our grid item does not fill 100% of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016766862%2FDq8-OWOQu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016766862%2FDq8-OWOQu.png" alt="grid-8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now we've got this empty space within our "grid area".  Would it be possible to center my grid item in the "grid area"?  Of course!  Here's the recipe:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;justify-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* horizontal */&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* vertical */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what we just did:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016794515%2F5-pvY8nFK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016794515%2F5-pvY8nFK.png" alt="grid-9.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See how our grid item is now centered in the "grid area"?  Here's the code–I suggest toggling these two CSS properties on and off in the CSS to visualize what it is doing.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/WNRjQaV?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Seems similar to Flexbox Alignment...?
&lt;/h3&gt;

&lt;p&gt;In Flexbox, we use the following two CSS properties to align items within their flex container:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;justify-content&lt;/code&gt; - aligns items on the "main axis"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;align-items&lt;/code&gt; - aligns items on teh "cross axis"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With CSS Grid, if we want to align grid items within their "grid areas", we use these properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;justify-items&lt;/code&gt; - aligns items in the horizontal direction within the grid area&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;align-items&lt;/code&gt; - aligns items in the vertical direction within the grid area&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CSS Grid also has the &lt;code&gt;justify-content&lt;/code&gt; and &lt;code&gt;align-content&lt;/code&gt; properties, but we aren't quite ready to explore those yet.&lt;/p&gt;

&lt;p&gt;To make this even more clear, let's add another grid item into the equation.  This time, it will occupy 2fr x 2fr units for the "grid area".  This means that the "grid area" dimensions will be 75px wide and tall (37.5 * 2).  We will make our second grid item 45px (arbitrary, anything less than 75px will work) wide and tall so that it has some "empty space" and we can see the effect of these alignment properties.  Here's what we're dealing with (without any alignment properties set yet):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016804473%2F7YiqsTE0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016804473%2F7YiqsTE0z.png" alt="grid-10.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go one step at a time.  First, we'll set the vertical alignment of the grid items within their "grid areas".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* vertical */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what we get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016814322%2FhqO7uthoxM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016814322%2FhqO7uthoxM.png" alt="grid-11.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we will set the horizontal alignment with &lt;code&gt;justify-items&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* vertical */&lt;/span&gt;
  &lt;span class="py"&gt;justify-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* horizontal */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, our grid items are now centered within their "grid areas".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016823735%2FUD1ux2NDe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016823735%2FUD1ux2NDe.png" alt="grid-12.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the relevant code:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/jOymWZV?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, I'm supplying you with visualizes that help you see what is happening, but how would we verify these things without them?&lt;/p&gt;

&lt;p&gt;Glad you asked–if you open up the Google Chrome Developer Tools (other browsers like Firefox work too), you will see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016845530%2FLTmT9g76I.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016845530%2FLTmT9g76I.png" alt="grid-container-dev-tools.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how our items are perfectly centered within their "grid areas".&lt;/p&gt;

&lt;h3&gt;
  
  
  Aligning the Entire Grid
&lt;/h3&gt;

&lt;p&gt;Up to this point, we have been working in "perfect conditions":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#212226&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our grid container HTML element has 300px of "available space" which is evenly filled with our grid itself (because of our &lt;code&gt;grid-template&lt;/code&gt; rules).  The &lt;code&gt;repeat(8, 1fr)&lt;/code&gt; rule is saying "I want 8 rows and 8 columns, and I want each grid cell to evenly divide the 300px of available space".  Therefore, in our examples so far, each grid cell is 37.5px wide and tall (300 / 8).&lt;/p&gt;

&lt;p&gt;What if we changed the rule to this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#212226&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our grid container's available space is 300px, but now, our grid is 200px wide and tall (25px * 8).  &lt;strong&gt;Our grid is smaller than our grid container.&lt;/strong&gt;  Here's a visual of what that might look like by default.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016855907%2FXKXm1OQ9U.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619016855907%2FXKXm1OQ9U.png" alt="grid-13.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's put our grid items back on.  Since we decreased the size of our grid, we need to decrease the size of our grid items.  Remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grid item 1 has a "grid area" equal to 4x4, which is equal to 100x100 pixels (25 * 4 = 100)&lt;/li&gt;
&lt;li&gt;Grid item 2 has a "grid area" equal to 2x2, which is equal to 50x50 pixels (25 * 2 = 50)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To ensure that the grid items are smaller than their "grid areas", let's make them 50x50 and 25x25 pixels respectively (exactly half the size of their "grid areas" in each case).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619017333396%2FxExcgl9Rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619017333396%2FxExcgl9Rk.png" alt="grid-14.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's what our CSS looks like so far:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#212226&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#1E4040&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#71D99E&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#71D99E&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#3A8C7D&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's throw a little curveball here to practice our grid item alignment skills.  Add the following CSS to your grid container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;justify-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will reposition both items to occupy the bottom-right corner of their "grid areas".  Here's what that looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619017778197%2Fj3cTni9rZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619017778197%2Fj3cTni9rZ.png" alt="grid-15.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  justify-content and align-content
&lt;/h3&gt;

&lt;p&gt;We are finally ready to see what these two properties do.  Once again–&lt;strong&gt;if the grid size is smaller than the grid container size&lt;/strong&gt;, these properties will align the ENTIRE grid within the grid container.  Let's go ahead and center our grid by adding these properties to the container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what we get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619017898596%2F0v9a9g9Wg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619017898596%2F0v9a9g9Wg.png" alt="grid-16.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above, it's obvious what is happening.  The entire grid is centered within the grid container and the grid items are placed at the end of their "grid areas".  Once we turn this into code, it's not so obvious:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/qBRmxEv?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;But once again, you can open your developer tools and hover over the grid to see a clearer picture of what's going on.  The developer tools do not highlight the "grid areas" that we talked about, so I added those in manually.  Since we defined our grid items to be perfect multiples of the grid area sizes, they fit perfectly within the grid cells.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018232833%2FMqjqhDqpU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018232833%2FMqjqhDqpU.png" alt="grid-17.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  More Grid Alignment Examples
&lt;/h3&gt;

&lt;p&gt;It would be overly tedious for me to create visuals for every possible alignment combination.  That is what &lt;a href="https://grid.malven.co/" rel="noopener noreferrer"&gt;cheat sheets&lt;/a&gt; are for.  Nevertheless, I want to give you a few more examples to look at to better understand these grid alignment properties.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 1
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018238709%2FSJtLGjPdL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018238709%2FSJtLGjPdL.png" alt="grid-18.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 2
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018296647%2FKN4-dzd9Z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018296647%2FKN4-dzd9Z.png" alt="grid-19.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 3
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018305974%2FAoQbz3GRn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018305974%2FAoQbz3GRn.png" alt="grid-20.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Grid Basics Summary
&lt;/h2&gt;

&lt;p&gt;At this point, I've shown you the basics of CSS Grid.  There is a lot more that you can do with it, but we've got the core concepts in place.&lt;/p&gt;

&lt;p&gt;Before moving on with the tutorial, you should feel comfortable explaining how the following CSS properties are used in the context of the CSS Grid system.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Container Properties

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;display: grid&lt;/code&gt; - activates the grid&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid-template-rows&lt;/code&gt; / &lt;code&gt;grid-template-columns&lt;/code&gt; - Defines the number of rows/columns in the grid&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;justify-content&lt;/code&gt; / &lt;code&gt;align-content&lt;/code&gt; - Aligns the entire grid (if it is smaller than its container)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;justify-items&lt;/code&gt; / &lt;code&gt;align-items&lt;/code&gt; - Aligns grid items within their "grid areas" (which are defined at the item level)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Grid Item Properties

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;grid-row-start&lt;/code&gt; / &lt;code&gt;grid-row-end&lt;/code&gt; - Defines the horizontal "grid area" for an item&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid-column-start&lt;/code&gt; / &lt;code&gt;grid-column-end&lt;/code&gt; - Defines the vertical "grid area" for an item&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  A Quick CSS Grid Challenge
&lt;/h3&gt;

&lt;p&gt;With your current knowledge, you should be able to create the design from the very beginning of this tutorial:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018323805%2F2c-vUVPMf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018323805%2F2c-vUVPMf.png" alt="grid-container.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is a starter Codepen (just hit the "fork" button to copy it to your account) along with the solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starter - &lt;a href="https://codepen.io/zg_dev/pen/JjENBKX" rel="noopener noreferrer"&gt;https://codepen.io/zg_dev/pen/JjENBKX&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Solution - &lt;a href="https://codepen.io/zg_dev/pen/gOgWjMo" rel="noopener noreferrer"&gt;https://codepen.io/zg_dev/pen/gOgWjMo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Solution (using shorthand Grid properties) - &lt;a href="https://codepen.io/zg_dev/pen/WNRjKEL" rel="noopener noreferrer"&gt;https://codepen.io/zg_dev/pen/WNRjKEL&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Intermediate CSS Grid
&lt;/h2&gt;

&lt;p&gt;The remainder of the tutorial will be an exploration of CSS Grid properties and how we can make the most out of this system.  While the following content is not &lt;strong&gt;required&lt;/strong&gt; to use CSS Grid effectively, I highly recommend reading all of it.  I do not intend to cover every remaining detail of CSS Grid, but rather point out the most useful parts that we haven't touched on thus far.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Grid "Gutters"
&lt;/h3&gt;

&lt;p&gt;When you make a grid on a web page, you're most likely going to want some spacing between your grid items.  We &lt;em&gt;could&lt;/em&gt; create this spacing with padding, margin, or even some Flexbox magic, but there is no need to when you have the power of CSS Grid.  We call this spacing "gutters" and it is easy to do with the &lt;code&gt;row-gap&lt;/code&gt; and &lt;code&gt;column-gap&lt;/code&gt; properties.&lt;/p&gt;

&lt;p&gt;Let's start with a basic 3x3 grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018338327%2FBTBESQouy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018338327%2FBTBESQouy.png" alt="grid-21.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the CSS Grid properties you need to create this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;4&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-5"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;5&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-6"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;6&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-7"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;7&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;8&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-9"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;9&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's add some gutters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;row-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;column-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yep, it's really that easy.  Just add your desired "gutter" width and your grid items will magically space themselves out in a responsive way.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/VwPbGGg?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;To reinforce some concepts from earlier, let's reduce the size of our grid and center it in its container.  Remember, we have 300px of space available within the grid container, so if we set the width/height of each grid "cell" to 50 pixels, the total grid size will now be 50 + 50 + 50 = 150px.  After doing that, we can use &lt;code&gt;justify-content&lt;/code&gt; and &lt;code&gt;align-content&lt;/code&gt; to center our grid in the grid container.  Here are the changes I'm making to achieve this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* REMOVE THIS 

  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(3, 1fr); 

  */&lt;/span&gt;

  &lt;span class="c"&gt;/* ADD THIS */&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/abpWaxj?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Grid Automatic Flow
&lt;/h3&gt;

&lt;p&gt;Do you remember from the Flexbox tutorial where we talked about the &lt;code&gt;flex-direction&lt;/code&gt; property?&lt;/p&gt;

&lt;p&gt;If you set the value to &lt;code&gt;row&lt;/code&gt;, your flex items would be horizontally aligned.  If set to &lt;code&gt;column&lt;/code&gt;, they would be vertically aligned.&lt;/p&gt;

&lt;p&gt;With CSS Grid, we don't have the concept of a "main axis" and "cross axis", but we do have the ability to change the natural flow of grid elements.&lt;/p&gt;

&lt;p&gt;Let's say you have a basic grid with the following HTML and CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;4&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we haven't explicitly defined where each grid item goes on the grid yet, where would you expect them to be?&lt;/p&gt;

&lt;p&gt;By default, they are aligned horizontally on the grid, and overflow to the next row if there are too many items.  In this case, we have 3 columns defined in our grid and 4 items, so the first three will line up horizontally, and the final item will break to the next row.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/QWdMPwz?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If we wanted, we could explicitly place each grid item to stack on top of each other vertically, but that's a lot of work!  If you wanted to change the "flow" of these grid items, all you need is the &lt;code&gt;grid-auto-flow&lt;/code&gt; property, which acts similarly to the Flexbox &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-flow#values" rel="noopener noreferrer"&gt;flex-direction&lt;/a&gt; property.  Most commonly, you will be using either &lt;code&gt;row&lt;/code&gt; (the default value) or &lt;code&gt;column&lt;/code&gt;.  Let's change it to &lt;code&gt;column&lt;/code&gt; and see what happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-flow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like that, our grid looks completely different!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/gOgxyeB?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also set this to &lt;code&gt;dense&lt;/code&gt;, which will look for empty spaces in your grid and place smaller grid items in them (even if they are not in the right order).  I won't be covering this here, but feel free to experiment with it as it could be good use-case for picture grids.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explicit vs. Implicit Grid
&lt;/h3&gt;

&lt;p&gt;Let's say we have this grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item gi-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;4&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/XWpejZd?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We have not explicitly placed or sized the grid items, which means they will do two things by default:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flow in the row direction (thanks to the default value of the &lt;code&gt;grid-auto-flow&lt;/code&gt; property set to &lt;code&gt;row&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Each item will stretch to fill its "grid area" (thanks to the default value of &lt;code&gt;justify-items&lt;/code&gt;, which is &lt;code&gt;stretch&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since we defined 3 columns and 1 row, the first 3 grid items will occupy the first row, and the 4th grid item will...  Occupy the 2nd row?  &lt;strong&gt;But wait, we didn't define a second row...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The fourth grid item is part of what we call the &lt;strong&gt;Implicit Grid&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's back up.  Our &lt;strong&gt;Explicit Grid&lt;/strong&gt; is a 1 x 3 (row x col) grid, defined by these properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Defines 1 row that fills the entire grid space */&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;/* Defines 3 columns of equal space */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Naturally, these allows 3 items to fit nicely in the grid.  If we have 4 or more items, they will start occupying the &lt;strong&gt;Implicit Grid&lt;/strong&gt;.  By default, "extra" items will flow according to the &lt;code&gt;grid-auto-flow&lt;/code&gt; property and will take up space equal to the size of their content.&lt;/p&gt;

&lt;p&gt;We can change this behavior with the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-rows" rel="noopener noreferrer"&gt;grid-auto-rows&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-columns" rel="noopener noreferrer"&gt;grid-auto-columns&lt;/a&gt; properties.  Instead of sizing the Implicit Grid according to content size, let's give it some dimensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c"&gt;/* Explicit Grid */&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c"&gt;/* Implicit Grid Behavior */&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-flow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* This is the default, but setting it anyways for demonstration */&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that any grid item placed on the Implicit Grid will have a height of 100px (row height) and width of 50px (column width).  Let's go ahead and place our 4th grid item on this Implicit Grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-4&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember, our explicit grid looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018374940%2FizfnoZAUV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018374940%2FizfnoZAUV.png" alt="grid-22.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the CSS above, we are saying, "place grid item 4 between RL-2 and RL-3, and between CL-4 and CL-5".  But wait, those don't exist?!&lt;/p&gt;

&lt;p&gt;Sure, they don't exist, but we can still place grid items on them.  The explicit grid will shrink and our grid item will be placed and sized on the &lt;strong&gt;Implicit Grid&lt;/strong&gt; according to the &lt;code&gt;grid-auto-rows&lt;/code&gt; and &lt;code&gt;grid-auto-columns&lt;/code&gt; properties, which are 100px and 50px respectively in this situation.  Therefore, our 4th grid item will be 100px tall and 50px wide.  See below:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/zYNEoPR?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Below, I have highlighted these concepts in more detail:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018387952%2FpPLK50lFB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018387952%2FpPLK50lFB.png" alt="grid-23.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After seeing this, you may have the question, "Why would we ever need this?".&lt;/p&gt;

&lt;p&gt;If you are ever building a grid where you don't know how many items you will have, it is a good practice to set the &lt;code&gt;grid-auto-rows&lt;/code&gt; and &lt;code&gt;grid-auto-columns&lt;/code&gt; properties.  If you want some flexibility, you can add something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing this, you are declaring that all grid items that fill the &lt;strong&gt;Implicit Grid&lt;/strong&gt; will have a minimum width and height of 50px and 100px respectively.  If those grid items have content larger then these dimensions, then their width and height will be set to auto.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Different Way to Use CSS Grid
&lt;/h3&gt;

&lt;p&gt;We are almost to the finish line.  The only property that we have not yet covered is the &lt;code&gt;grid-template-areas&lt;/code&gt; property.  I saved this for last because it is not necessary to use, but provides an easy way to define "grid areas".  Up to this point, we placed grid items using the following method:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/gOgWjMo?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We first define the grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;310px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#212226&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we explicitly place each grid item using the grid "lines":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the &lt;code&gt;grid-template-areas&lt;/code&gt;, we can achieve the same result in a different way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-areas&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="s1"&gt;"item1 item1 item3"&lt;/span&gt;
      &lt;span class="s1"&gt;"item2 . item3"&lt;/span&gt;
      &lt;span class="s1"&gt;". . item3"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.gi-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/mdRBwdJ?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The syntax here looks odd, but it is a much more "visual" way to use CSS Grid.  In the &lt;code&gt;.grid-container&lt;/code&gt; styles, notice how we have 3 quotation groups separated by spaces.  Since we have defined a 3x3 grid, the quotation groups represent the rows while the individual items represent the columns.  Furthermore, the &lt;code&gt;.&lt;/code&gt; represents "empty space".&lt;/p&gt;

&lt;p&gt;In each grid item style, we are defined that item's "alias" which as you can see, is used above in the &lt;code&gt;grid-template-areas&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let me format this so it is clearer what is happening:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"item1    item1    item3"
"item2      .      item3"
"  .        .      item3"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how "item3" fills the entire 3rd column?  Take a look at the Codepen above.&lt;/p&gt;

&lt;p&gt;You can quickly see what's going on here and for some, this is a more intuitive way to create grids.&lt;/p&gt;

&lt;h3&gt;
  
  
  Naming your Grid Lines
&lt;/h3&gt;

&lt;p&gt;In the above section, we talked about a more intuitive way to create a CSS Grid.  This section will offer another alternative.&lt;/p&gt;

&lt;p&gt;You've seen this already:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018406112%2Fl-c_A4_FG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1619018406112%2Fl-c_A4_FG.png" alt="grid-24.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For educational purposes, I have been labeling the grid "lines" as "CL-n" and "RL-n" to indicate "Column Line 1" and "Row Line 1", but when we translate this into CSS, it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we needed a way to remember the line names, we could assign them on the grid container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;RL-1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;RL-2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;RL-3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;RL-4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CL-1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CL-2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CL-3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CL-4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then use them on the grid items:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.gi-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;RL-1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-row-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;RL-2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CL-1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-column-end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CL-3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a demo:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/mdRBqXr?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Grid and Flexbox Work Together
&lt;/h2&gt;

&lt;p&gt;I said at the beginning of this tutorial that we would go through an example so you can see how Flexbox and CSS Grid play nicely together.  As a refresher, here are a few rules-of-thumb to go by when deciding between Flexbox and Grid:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Grid when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need full control of rows AND columns (examples: full page layouts, gallery items)&lt;/li&gt;
&lt;li&gt;You want to explicitly define the layout regardless of content size (i.e. if you are using Flexbox and it starts to get really complicated with a bunch of heights and widths, you probably should be using Grid)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Flexbox when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your content is a row OR column (examples: horizontal navbar, vertical sidebar)&lt;/li&gt;
&lt;li&gt;You want the size of items to determine layout&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below, I have created two examples that use CSS Grid and Flexbox interchangeably.  I suggest spending 10 minutes reading through the CSS of each.&lt;/p&gt;

&lt;h3&gt;
  
  
  Picture Gallery
&lt;/h3&gt;

&lt;p&gt;A simple picture gallery with a "sticky" navbar and footer.  This layout would require a few "hacky" CSS tricks to achieve before, but with Grid and Flexbox, it is relatively straightforward.  In particular, there are a few critical pieces to this that you should focus on while reading through the code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Notice how I have placed a "grid inside a grid".  This is perfectly okay.&lt;/li&gt;
&lt;li&gt;Notice that the main &lt;code&gt;grid-container&lt;/code&gt; has a &lt;code&gt;100vh&lt;/code&gt; height, and has set the main content (the pictures) to a unit of &lt;code&gt;1fr&lt;/code&gt;.  This means that the navbar and footer will get their explicitly defined heights of 70px and 40px and the picture grid will take up the remaining space in the viewport (visible screen).&lt;/li&gt;
&lt;li&gt;Notice that I set the &lt;code&gt;.pictures&lt;/code&gt; grid to have an &lt;code&gt;overflow: scroll&lt;/code&gt; setting.  This ensures that adding pictures to the grid will not cause our navbar or footer to disappear on scroll.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/RwKLKXg?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  The "Holy Grail" Layout
&lt;/h3&gt;

&lt;p&gt;This is the "final project" for our CSS Grid tutorial.  You will have to build this (or something very similar) many times in your web dev career, so I wanted to give you a template to start with!&lt;/p&gt;

&lt;p&gt;If you would like to build this with me, I created a &lt;a href="https://youtu.be/46Dh-VtBja4" rel="noopener noreferrer"&gt;YouTube video showing you how&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://zachgoll.github.io/holy-grail-css-layout/" rel="noopener noreferrer"&gt;Here's the final product.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you leave
&lt;/h2&gt;

&lt;p&gt;Thanks for reading!  If you liked this and want to support me, you can do two things that I would really appreciate.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Follow me on Twitter @zg_dev&lt;/li&gt;
&lt;li&gt;Subscribe to my email list below&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>html</category>
    </item>
    <item>
      <title>Detailed Flexbox Tutorial for Complete Beginners #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Sun, 28 Mar 2021 20:23:32 +0000</pubDate>
      <link>https://dev.to/zachgoll/detailed-flexbox-tutorial-for-complete-beginners-fullstackroadmap-4g78</link>
      <guid>https://dev.to/zachgoll/detailed-flexbox-tutorial-for-complete-beginners-fullstackroadmap-4g78</guid>
      <description>&lt;p&gt;This lesson is also on YouTube:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=heg9yalZZSc"&gt;Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=yeiYrKm6r0U"&gt;Part 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=YreJRElqfME"&gt;Part 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=rEYa5r3VKo4"&gt;Part 4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/7-html-crash-course/"&gt;A basic understanding of HTML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/8-css-crash-course/"&gt;A basic understanding of CSS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;By the end of this lesson, you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be able to explain to someone what Flexbox is&lt;/li&gt;
&lt;li&gt;Understand how Flexbox can make your workflow faster and WAYYYY less frustrating&lt;/li&gt;
&lt;li&gt;Have a firm understanding of basic Flexbox syntax and patterns&lt;/li&gt;
&lt;li&gt;Build the following design with Flexbox:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09vdiy9stexpyrcsjtlf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09vdiy9stexpyrcsjtlf.jpg" alt="testimonial grid" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What we are covering in this lesson
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What is Flexbox?&lt;/li&gt;
&lt;li&gt;What can Flexbox do for us?

&lt;ul&gt;
&lt;li&gt;Simplify layouts in CSS&lt;/li&gt;
&lt;li&gt;Reduce reliance on media queries for responsive design&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Basic Flexbox Concepts

&lt;ul&gt;
&lt;li&gt;Flex container vs. Flex items&lt;/li&gt;
&lt;li&gt;Main axis vs. Cross axis&lt;/li&gt;
&lt;li&gt;Aligning and spacing flex items&lt;/li&gt;
&lt;li&gt;Flex wrap&lt;/li&gt;
&lt;li&gt;Flex sizing&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;A Frontend Mentor HTML/CSS Challenge with Flexbox!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is the "fullstackroadmap" series?
&lt;/h2&gt;

&lt;p&gt;This is part of my fullstack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first fullstack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Begin - What is Flexbox?
&lt;/h2&gt;

&lt;p&gt;Flexbox is a &lt;strong&gt;one-dimensional CSS layout system&lt;/strong&gt; enabled by a single CSS property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By setting this property on an HTML element, all of that element's direct children will behave in a totally different way than we previously discussed.&lt;/p&gt;

&lt;p&gt;Remember from our &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/8-css-crash-course/"&gt;CSS crash course&lt;/a&gt; when we talked about the "normal flow" of HTML elements?  We talked about &lt;code&gt;block&lt;/code&gt;, &lt;code&gt;inline-block&lt;/code&gt;, and &lt;code&gt;inline&lt;/code&gt; HTML elements.  To review:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block element&lt;/strong&gt; - Breaks to a new line, respects width/height properties, 100% width of container by default&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inline Block element&lt;/strong&gt; - Respects width/height properties, but does not break to a new line and does not take up 100% width of container by default&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inline element&lt;/strong&gt; - Does not break, does not respect width/height properties, does not take up 100% width of container by default&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the "default" display types.  By adding &lt;code&gt;display: flex&lt;/code&gt; to an HTML element, we can unlock a tremendous amount of possibilities!&lt;/p&gt;

&lt;h2&gt;
  
  
  What Can Flexbox Do for Us?
&lt;/h2&gt;

&lt;p&gt;I could tell you or I could show you.  Plenty of resources tell you.  Let me show you.&lt;/p&gt;

&lt;p&gt;Here is a CSS layout WITHOUT using Flexbox.  Read through the CSS and particularly pay attention to the "layout properties" section.  Notice how I am using lots of widths and margins to get the layout how I want it.  Before Flexbox was released, this is how you might write the CSS.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/BaQMKZR"&gt;Float Layout (legacy layouts)&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/BaQMKZR?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now that we have Flexbox, we can achieve the same layout with a lot less CSS.  Notice how many lines of CSS we were able to remove below.  Also, notice that we no longer need a bunch of percentages, floats, and absolute positioning to achieve this layout!&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/wvoNGjr"&gt;Flexbox Layout&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/wvoNGjr?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's look at another example.  In the Codepen below, I have centered a &lt;code&gt;div&lt;/code&gt; container to the middle of the screen WITHOUT using Flexbox.  This requires a few CSS tricks that are not all that intuitive!&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/OJbdXWE"&gt;Centering Elements Without Flexbox&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/OJbdXWE?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The next example is identical to above except now, we are leveraging flexbox to easily center this div.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/qBqgNmR"&gt;Centering Elements With Flexbox&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/qBqgNmR?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In that last example, we went from this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Legacy solution */&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.div-to-center&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Flexbox solution */&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.div-to-center&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my opinion, our Flexbox solution is simpler and easier.&lt;/p&gt;

&lt;p&gt;In summary, here are the main reasons why you should learn Flexbox.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easier to design responsively&lt;/li&gt;
&lt;li&gt;Less CSS code&lt;/li&gt;
&lt;li&gt;Less calculations&lt;/li&gt;
&lt;li&gt;Aligning and centering content is WAY EASIER&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  From Floats to Flexbox and Grid
&lt;/h3&gt;

&lt;p&gt;Before Flexbox, web developers used "floats", "clearfixes", and a bunch of other "hacks" to get the layout of their webpage looking good.  CSS was never intended for complex layouts in the beginning, so when websites started using navbars, sidebars, footers, and other layouts, they needed to find a "workaround" to their problems.&lt;/p&gt;

&lt;p&gt;When Flexbox was introduced, the CSS layout game changed.  We can now easily build complex layouts without "CSS Tricks".&lt;/p&gt;

&lt;p&gt;But shortly after Flexbox came about, this thing called "CSS Grid" was released into most major browsers.  Like Flexbox, CSS Grid aims to make CSS layouts easier.&lt;/p&gt;

&lt;p&gt;If that's the case, why are we learning Flexbox?  Why not skip it and learn CSS Grid?  Here are two reasons why:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Flexbox and CSS Grid are NOT mutually exclusive.  They work together.  I'll show you how in future lessons.&lt;/li&gt;
&lt;li&gt;Flexbox is "required" knowledge for the modern front-end web developer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The next lesson of this full-stack series will be about CSS Grid, and luckily, it follows a very similar structure to Flexbox.  In other words, learning Flexbox will help you learn CSS Grid quicker.&lt;/p&gt;

&lt;p&gt;While we will not be covering CSS Grid in this lesson, many of the concepts here will carry forward to when we do learn it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Flex Containers vs. Items
&lt;/h2&gt;

&lt;p&gt;We have already used the concept of "containers" in previous lessons, but we haven't looked at it in isolation.  Take a read below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some random HTML&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sub-container-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unimpressive, I know, but the structure above highlights a &lt;strong&gt;crucial concept&lt;/strong&gt; in CSS, and particularly, Flexbox layouts.  In this structure, we have a &lt;code&gt;main-container&lt;/code&gt; div, which has three "children" containers.  One of the child containers, &lt;code&gt;container-1&lt;/code&gt;, has a child container itself.&lt;/p&gt;

&lt;p&gt;This pattern is important to understand because when using Flexbox, we ALWAYS need to be aware of which HTML element is the "container" and which HTML element(s) are the "child elements" of that container.&lt;/p&gt;

&lt;p&gt;Without any CSS added, all of the &lt;code&gt;div&lt;/code&gt; elements above are "block" elements.  But what if we did this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This single CSS rule turns the &lt;code&gt;main-container&lt;/code&gt; div into a "flex container".  This also means that all of this container's direct children are now "flex items".  In this case, there are four total HTML elements affected:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;main-container&lt;/code&gt; - becomes a "flex container"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;container-1&lt;/code&gt; - becomes a "flex item"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;container-2&lt;/code&gt; - becomes a "flex item"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;container-3&lt;/code&gt; - becomes a "flex item"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We'll talk about what this means shortly, but what about the rest of the HTML elements?  What about &lt;code&gt;sub-container-1&lt;/code&gt;?  What about the &lt;code&gt;p&lt;/code&gt; element?  What about the &lt;code&gt;ul&lt;/code&gt; and &lt;code&gt;li&lt;/code&gt; elements?&lt;/p&gt;

&lt;p&gt;Listen up, you're going to need to remember this–&lt;strong&gt;only direct children of "flex containers" are "flex items"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What if I did this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.container-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Certainly, a "flex container" cannot be a "flex item" too right?!  &lt;/p&gt;

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

&lt;p&gt;A single HTML element can be both.  This will make more sense soon.&lt;/p&gt;

&lt;p&gt;Let's do some more practice identifying "flex containers" and "flex items".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"left-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Some heading&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some paragraph text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"right-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;H3 Heading&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.left-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given the HTML and CSS above, name all the flex containers, flex items, and "block" items.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flex containers&lt;/strong&gt; - &lt;code&gt;.main-container&lt;/code&gt; and &lt;code&gt;left-container&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flex items&lt;/strong&gt; - &lt;code&gt;.left-container&lt;/code&gt;, &lt;code&gt;.right-container&lt;/code&gt;, &lt;code&gt;h2&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block items&lt;/strong&gt; - &lt;code&gt;h3&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we go through this tutorial, be sure to identify the "flex container" and its "flex items" before writing any additional code!&lt;/p&gt;

&lt;h2&gt;
  
  
  Flex Container Flex Item Properties
&lt;/h2&gt;

&lt;p&gt;At this point, you know how to activate Flexbox on an HTML element (&lt;code&gt;display: flex&lt;/code&gt;), and you know how to identify the "flex container" and "flex items".&lt;/p&gt;

&lt;p&gt;As we go through the remainder of this tutorial, my intention is NOT to regurgitate Flexbox documentation.  My goal is to logically step through how this entire system works.  Therefore, I want to start by providing you with a few resources to have open as we go through this.&lt;/p&gt;

&lt;p&gt;Consistent with previous tutorials, I want to provide you with links to the MDN documentation on Flexbox.  Below are links to documentation.  &lt;strong&gt;I will explain each of these in detail throughout the post.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Flex Container" CSS Properties

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout"&gt;display: flex&lt;/a&gt; - Activates Flexbox on an HTML element&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction"&gt;flex-direction&lt;/a&gt; - Defines the "main" and "cross" axis&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content"&gt;justify-content&lt;/a&gt; - Defines the alignment of flex items on the main axis&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items"&gt;align-items&lt;/a&gt; - Defines the alignment of flex items on the cross axis&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap"&gt;flex-wrap&lt;/a&gt; - For overflowing content, defines whether it will "wrap" to the next line&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-content"&gt;align-content&lt;/a&gt; - Only applies if &lt;code&gt;flex-wrap&lt;/code&gt; is set to &lt;code&gt;wrap&lt;/code&gt;, and defines the alignment of all the wrapped content on the cross axis (I know, a bit confusing)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;"Flex Item" CSS Properties

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-self"&gt;align-self&lt;/a&gt; - Similar to align-items and align-content above, but only applies to a single flex item&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/order"&gt;order&lt;/a&gt; - Change the order of flex items &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow"&gt;flex-grow&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink"&gt;flex-shrink&lt;/a&gt;, and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis"&gt;flex-basis&lt;/a&gt; - All properties related to how large the flex item will be in the container.  These are probably the trickiest of all properties, but we'll walk through them.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A quick note on "shorthand" flex properties&lt;/strong&gt; - If you read the docs, you'll notice that I have left out properties like &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex"&gt;flex&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-flow"&gt;flex-flow&lt;/a&gt;.  These are "shorthand" properties that combine two or more other properties.  For example, &lt;code&gt;flex&lt;/code&gt; combines &lt;code&gt;flex-grow&lt;/code&gt;, &lt;code&gt;flex-shrink&lt;/code&gt;, and &lt;code&gt;flex-basis&lt;/code&gt; while &lt;code&gt;flex-flow&lt;/code&gt; combines &lt;code&gt;flex-direction&lt;/code&gt; and &lt;code&gt;flex-wrap&lt;/code&gt;.  Since we are just learning, there is NO NEED for these yet.  Once you are completely comfortable with the long-hand properties, you can start using these, but not before.&lt;/p&gt;

&lt;p&gt;Lastly, before we get started, I want to point you towards an excellent "cheat sheet" for Flexbox.  For the first couple weeks of working with Flexbox, I had &lt;a href="https://yoksel.github.io/flex-cheatsheet"&gt;this cheatsheet&lt;/a&gt; open in my browser at all times.&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Properties
&lt;/h3&gt;

&lt;p&gt;Just like there are default margins, colors, display types, and other property defaults in CSS, Flexbox comes with some defaults.  Remember, creating a Flex Container is easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph element 1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph element 2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph element 3&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you write that CSS, a series of "defaults" will be applied to the flex container and items in it.  In other words, the CSS in the above code snippet is equivalent to the CSS below.  &lt;a href="https://codepen.io/zg_dev/pen/KKNJZrW"&gt;Here is a Codepen&lt;/a&gt; to prove it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/*  
    You could delete everything below, and nothing will change.  All of
    the properties below are "defaults" and are applied automatically

    Please note that "normal" and "auto" will adopt different behavior 
    based on different situations.  I have commented what this "normal" value
    resolves to with Flexbox.
  */&lt;/span&gt;
&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* stretch */&lt;/span&gt;
  &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* stretch */&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;nowrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;align-self&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-grow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-shrink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-basis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we go through this tutorial, remember that if we do not explicitly set these properties, they will default to the above values!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Main Axis vs. Cross Axis (flex-direction)
&lt;/h2&gt;

&lt;p&gt;Once an HTML element becomes a "flex container", you have to think about it differently.  By default, each flex container looks something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvs58yeu0l203kv0ly6hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvs58yeu0l203kv0ly6hw.png" alt="default flex container" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each flex container will take up space (width, height) and the flex items within it will be placed along either the main or cross axis.&lt;/p&gt;

&lt;p&gt;We can determine the main and cross axis based on the &lt;code&gt;flex-direction&lt;/code&gt; property, which is by default, set to &lt;code&gt;row&lt;/code&gt;.  This tells us that the main axis is &lt;strong&gt;horizontal&lt;/strong&gt; and the cross axis is &lt;strong&gt;vertical&lt;/strong&gt;.  If you need to change the direction of the main/cross axes, you can do so like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what this does:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vkml4vzku6ew9ofbary.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vkml4vzku6ew9ofbary.png" alt="altered flexbox" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Changing this single property changes the main and cross axes, which influences how the flex items are arranged within the flex container.  In the Codepen below, click the button to toggle between the two states.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/oNYmBZZ"&gt;Default Flexbox&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/oNYmBZZ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  What if the container size changes?
&lt;/h3&gt;

&lt;p&gt;In the Codepen example above, I gave the flex container a width of &lt;code&gt;300px&lt;/code&gt; and a height of &lt;code&gt;200px&lt;/code&gt;.  What if I omitted these?&lt;/p&gt;

&lt;p&gt;Just like regular block elements, a flex container without explicit height/width values will occupy 100% width and the height will be based on the height of the content within.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/YzpBVGP"&gt;Flex Direction without explicit container dimensions&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/YzpBVGP?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  An Important Preface to the Rest of This Post
&lt;/h2&gt;

&lt;p&gt;For the remainder of this post, I will be using the following flex settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* main axis is horizontal, cross axis is vertical */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It would be redundant to show examples with a &lt;code&gt;flex-direction&lt;/code&gt; of both &lt;code&gt;row&lt;/code&gt; AND &lt;code&gt;column&lt;/code&gt;.  Since we will be working with a main axis that is horizontal, all our calculations will be done on the "width" property of elements, but if the main axis was &lt;code&gt;column&lt;/code&gt;, we would have to look at the "height" property.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alignment of Flex Items
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Main Axis Alignment (justify-content)
&lt;/h3&gt;

&lt;p&gt;By using the &lt;code&gt;justify-content&lt;/code&gt; property on the flex container, you can influence how the flex items are aligned on the main axis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;default&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="n"&gt;space-around&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="n"&gt;space-evenly&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Use this to align items on the main axis */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are six values here that you'll want to know.  You can &lt;a href="https://yoksel.github.io/flex-cheatsheet/#section-justify-content"&gt;test them out here&lt;/a&gt;, or see them visually below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5jf28tthdi3q1wghwygg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5jf28tthdi3q1wghwygg.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8y8ucumj1ow06fwsqxf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8y8ucumj1ow06fwsqxf.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5hnz0t3ujv75ptqtessf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5hnz0t3ujv75ptqtessf.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09swvxccido4dc28maid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09swvxccido4dc28maid.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsm0vdz69yms1sz14e2q7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsm0vdz69yms1sz14e2q7.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39utnhzrmfc69tyd6f4l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39utnhzrmfc69tyd6f4l.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a clarification, the difference between &lt;code&gt;space-around&lt;/code&gt; and &lt;code&gt;space-evenly&lt;/code&gt; is subtle, but there is a difference.  With &lt;code&gt;space-around&lt;/code&gt;, the &lt;em&gt;space between&lt;/em&gt; flex items will be equal, but the space on the edges will not.  With &lt;code&gt;space-evenly&lt;/code&gt;, all empty space will be equal.&lt;/p&gt;
&lt;h3&gt;
  
  
  Cross Axis Alignment (align-items)
&lt;/h3&gt;

&lt;p&gt;In addition to alignment on the main axis, we can align on the cross axis.&lt;/p&gt;

&lt;p&gt;Before we look at the possibilities, I want to bring your attention to something.  In the above examples, you'll notice that all the flex items occupy 100% height.  This is because the default value for &lt;code&gt;align-items&lt;/code&gt; is &lt;code&gt;normal&lt;/code&gt; (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items#formal_definition"&gt;see docs&lt;/a&gt;).  The value "normal" can mean different things in different situations.  In this case, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items#values"&gt;"normal" means "stretch"&lt;/a&gt;, which will automatically "stretch" the height of flex items to fit the height of the flex container.&lt;/p&gt;

&lt;p&gt;Once we start applying some of these cross axis alignment values, you will notice that the flex items will no longer "stretch" to be the full height of the container.&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;align-items&lt;/code&gt; property, there are five main values.  Depending on the "natural" height of each flex item, these will look different.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1kh9ov64ds8crff6x7pq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1kh9ov64ds8crff6x7pq.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3acw4wwl33vq5ltps3a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3acw4wwl33vq5ltps3a.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foicdnex42sw7f8ucnbbv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foicdnex42sw7f8ucnbbv.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexud727zx82loxlw9f8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexud727zx82loxlw9f8q.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qek6rxvirocfjfdc9iq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qek6rxvirocfjfdc9iq.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Overflowing flex items
&lt;/h3&gt;

&lt;p&gt;So far, we have looked at simple examples.  But what if you have so many flex items in a flex container that they don't fit within the defined space?&lt;/p&gt;

&lt;p&gt;To illustrate this, let's put together the following scenario:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flex Container size

&lt;ul&gt;
&lt;li&gt;4px border&lt;/li&gt;
&lt;li&gt;408px width (we will use border-box sizing, so need to add left + right border of 4px each to get 8px, and then add that to total width of 400px to get 408px)&lt;/li&gt;
&lt;li&gt;200px height&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Flex items size

&lt;ul&gt;
&lt;li&gt;50px width&lt;/li&gt;
&lt;li&gt;50px height&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this scenario, you can fit a total of 8 flex items within the flex container (50px * 8 = 400px).  Looks pretty good so far–if you inspect this Codepen with dev tools, you can confirm that each flex item is exactly 50x50 pixels.&lt;/p&gt;


  See the Pen &lt;a href="https://codepen.io/zg_dev/pen/jOVJEZW"&gt;flex-wrap and align-content (improper usage)&lt;/a&gt; by Zach 
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.


&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/jOVJEZW?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;But what if we doubled the number of squares?  Instead of 8, we had 16?  Here's what happens.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/bGBZNxd"&gt;flex-wrap and align-content (improper usage)&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/bGBZNxd?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;There are a few weird things going on here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It appears that most of these flex items are &lt;strong&gt;NOT&lt;/strong&gt; 50px wide (actually, none of them are).  We set a width of 50px, so why is this happening?&lt;/li&gt;
&lt;li&gt;Flex items overflowing the container, which is clearly a problem we will want to fix.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you work with Flexbox, if the total dimensions of the flex items exceed the dimensions of the flex container, they will first shrink to their smallest possible dimensions, and if they still do not fit in the container, they will overflow.&lt;/p&gt;

&lt;p&gt;If items are overflowing outside your container, you have two options: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Specify what you want to do with the overflowing flex items&lt;/li&gt;
&lt;li&gt;Wrap the overflowing flex items to the next line&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In CSS (not just Flexbox), there is a property called &lt;code&gt;overflow&lt;/code&gt; that you can specify on a container to define how it handles overflowing content.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/overflow"&gt;Here are the possible options&lt;/a&gt;.  If you set this property to &lt;code&gt;overflow: auto&lt;/code&gt; on the container, a scrollbar will appear and the overflowing flex items will hide.  You can then scroll to see them!&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/rNWRaQG"&gt;flex-wrap and align-content (overflow property)&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/rNWRaQG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;But if you are creating a grid of items, you probably don't want your users to have to scroll to see all of them.  You probably want to just wrap them to the next line.  Instead of setting the &lt;code&gt;overflow&lt;/code&gt; CSS property, we can set the &lt;code&gt;flex-wrap&lt;/code&gt; property on the flex container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what happens when we do that.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/ExNMaGQ"&gt;flex-wrap&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/ExNMaGQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Looks a lot better right?  But what's up with that whitespace between the items?&lt;/p&gt;

&lt;p&gt;We just talked about &lt;code&gt;align-items&lt;/code&gt; earlier, so you might be inclined to try something like this to fix that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex-start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* This should remove the whitespace right??... */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By now, I hope you're getting used to me saying this but... When we added the &lt;code&gt;flex-wrap&lt;/code&gt; property, &lt;strong&gt;the rules of the game changed.  Again.&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;When we set this property to anything other than the default, we now must use &lt;code&gt;align-content&lt;/code&gt; rather than &lt;code&gt;align-items&lt;/code&gt; to position the wrapped flex items on the cross axis.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-content"&gt;Here are the possible values&lt;/a&gt;.  They are basically the same as the values for &lt;code&gt;align-items&lt;/code&gt;.  We'll go with &lt;code&gt;flex-start&lt;/code&gt; to put all of the items at the beginning of the container and remove that whitespace in the middle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex-start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Use align-content when flex-wrap: wrap is set.  Otherwise, use align-items */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what that looks like:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/RwodNvm"&gt;flex-wrap + align-content&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/RwodNvm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Just remember, if &lt;code&gt;flex-wrap&lt;/code&gt; is set to anything OTHER THAN &lt;code&gt;nowrap&lt;/code&gt; (default), use &lt;code&gt;align-content&lt;/code&gt;, NOT &lt;code&gt;align-items&lt;/code&gt; to arrange flex item groups on the cross axis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flex Item Properties
&lt;/h2&gt;

&lt;p&gt;To this point, we have covered all the flex container CSS properties, but that's not all we can do!  At the flex-item level, we can do two main things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Change the alignment of a flex item&lt;/li&gt;
&lt;li&gt;Change the size of a flex item&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's start with the first one because it is a much simpler discussion.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aligning a single flex item
&lt;/h3&gt;

&lt;p&gt;If you want to take a single flex item and align it differently than the rest, you can use the &lt;code&gt;align-self&lt;/code&gt; property.  Remember though, this CSS rule must be applied to that individual item, NOT the container.&lt;/p&gt;

&lt;p&gt;Look at this magic:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/ZEBPLMz"&gt;Align Self&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/ZEBPLMz?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Feel free to click on the CSS of the Codepen, but here's a summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flex items 1, 5 - &lt;code&gt;align-self: flex-start&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Flex items 2, 4, 6, 8 - &lt;code&gt;align-self: center&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Flex items 3, 7 - &lt;code&gt;align-self: flex-end&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sizing flex items
&lt;/h3&gt;

&lt;p&gt;In my opinion, this is the hardest part of Flexbox, but if you have a solid understanding of everything above, it shouldn't be too overwhelming.&lt;/p&gt;

&lt;p&gt;With the prior examples above, we set explicit width and height properties on our flex items (50x50 pixels).  When the total dimensions of these items does NOT exceed that of the flex container, we see that they maintain these width and height properties of 50x50, but when we add too many, they start to shrink to try and fit into the container, and then overflow (if we omit the &lt;code&gt;flex-wrap: wrap&lt;/code&gt; property).&lt;/p&gt;

&lt;p&gt;While it might seem obvious why an element with &lt;code&gt;width: 50px&lt;/code&gt; is 50 pixels wide, when dealing with Flexbox, this does not tell the entire story!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;flex-grow: 0&lt;/code&gt; - If (and only if) the main axis has extra space, this is the factor which an item will "grow" to fit that empty space (we will explore this more later).  The value of &lt;code&gt;0&lt;/code&gt; means that by default, the item will NOT grow to fit the remaining space.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flex-shrink: 1&lt;/code&gt;- If (and only if) the main axis DOES NOT have extra space, this factor determines whether the flex item will "shrink to fit" or not.  The value of &lt;code&gt;1&lt;/code&gt; means that by default, the item will shrink to fit the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flex-basis: auto&lt;/code&gt; - The value "auto" is another way of saying, "look at my height and width properties for sizing".  In our example above, a value of "auto" here means that each flex item will equal 50x50 pixels (because that's what we set the width and height to).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  flex-grow
&lt;/h4&gt;

&lt;p&gt;I know this is confusing, but let's take a look at the following example and reason through it.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/LYbaWqJ"&gt;Flex Sizing&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/LYbaWqJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this example, we have the following conditions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;50x50 pixel flex items (x4)&lt;/li&gt;
&lt;li&gt;408px width flex container w/4px border (so effectively, this is a 400px wide container, which can fit 8 total flex items of the above size)&lt;/li&gt;
&lt;li&gt;All flex items: &lt;code&gt;flex-grow: 0&lt;/code&gt; (the default)&lt;/li&gt;
&lt;li&gt;All flex items: &lt;code&gt;flex-shrink: 1&lt;/code&gt; (the default)&lt;/li&gt;
&lt;li&gt;All flex items: &lt;code&gt;flex-basis: auto&lt;/code&gt; (the default)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since we have four flex items with 50px widths, that means that the total space on the main axis is allocated as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Occupied space: 200px (50px * 4 items)&lt;/li&gt;
&lt;li&gt;Unoccupied space: 200px (Total width - Occupied space)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcr8nmy0fzlnxax646iw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcr8nmy0fzlnxax646iw.png" alt="Alt Text" width="500" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the moment, all four of our flex items have a &lt;code&gt;flex-grow&lt;/code&gt; factor of 0.  This means that if there is empty space (which there is, 200px), each item will take up 0% of it.  Let's say we wanted to change this rule to say that if there is empty space, items 2 and 4 will each occupy 50% of it.  Here's how we would write that in CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-grow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-grow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-grow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-4&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-grow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is what that looks like in real life:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/JjbzyMM"&gt;flex-grow example #1&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/JjbzyMM?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now here is where it gets a bit confusing.  By specifying a &lt;code&gt;flex-grow&lt;/code&gt; value of &lt;code&gt;1&lt;/code&gt;, that doesn't mean that the item gets 100% of the empty space.  To calculate how much empty space it will occupy, you have to look at all the flex items in the container and sum their &lt;code&gt;flex-grow&lt;/code&gt; values together.&lt;/p&gt;

&lt;p&gt;Let's do some simple math:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Total "empty" or "unallocated" space equals 200 pixels&lt;/li&gt;
&lt;li&gt;Total &lt;code&gt;flex-grow&lt;/code&gt; values = 0 + 1 + 0 + 1 = 2 "units of space"&lt;/li&gt;
&lt;li&gt;200 pixels / 2 units = 100 pixels, so each "unit" equals 100 pixels&lt;/li&gt;
&lt;li&gt;Flex items 2 and 4 both get a single unit, so they both will equal their original width (50px) + 100px (one unit) of unoccupied space for a total of 150px of total width.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go ahead, open up the Codepen and check the widths in dev tools!&lt;/p&gt;

&lt;h4&gt;
  
  
  flex-shrink
&lt;/h4&gt;

&lt;p&gt;To understand this, we need to have an example where there are too many flex items for the container.  Instead of 4 flex items (which leaves 200px empty space), let's go with 9 flex items, which will overflow by 50px.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/ExNMveb"&gt;flex-grow example #2a&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/ExNMveb?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Hold the phone here!  If the total available width in this flex container is 400px and we just added 9 flex items that are 50px each (9 * 50 = 450px), then how on earth are they all fitting in the container?&lt;/p&gt;

&lt;p&gt;This works because by default, all flex items have a &lt;code&gt;flex-shrink&lt;/code&gt; value of &lt;code&gt;1&lt;/code&gt;.  This means that if we "overflow" by 50px, each flex item will take an equal share of that overflow and shrink by that amount (so long as it doesn't shrink the items less than the size of their content).&lt;/p&gt;

&lt;p&gt;Let's break it down again:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;400px total width&lt;/li&gt;
&lt;li&gt;9 flex items at a width of 50px each = 450px, so there is 50px of "overflow"&lt;/li&gt;
&lt;li&gt;Each flex item: &lt;code&gt;flex-shrink: 1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;9 flex items, so adding the &lt;code&gt;flex-shrink&lt;/code&gt; values up, we get 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 9 units&lt;/li&gt;
&lt;li&gt;50px of overflow / 9 units = 5.55px&lt;/li&gt;
&lt;li&gt;So... each flex item will reduce from an original size of 50px to a size of 50px - 5.55px = 44.45px&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go ahead, open up dev tools and check.  Each flex item should now have a width of 44.45px.&lt;/p&gt;

&lt;p&gt;But wait a minute... Didn't we try this "overflow" thing before and some flex items broke out of the main container?  &lt;/p&gt;

&lt;p&gt;Yes.  Each flex item can only shrink so far.  Eventually, it reaches its smallest possible width, which is the width of its inner content.  This inner content width cannot be easily derived, but if you are really curious, &lt;a href="https://stackoverflow.com/a/294273/7437737"&gt;here's a SO answer that addresses it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Anyways, here is our example from above, but this time, we have 1 too many flex items.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/KKNEvjN"&gt;flex-grow example #2b&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/KKNEvjN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you delete flex item 12 from the HTML, all the items will fit again.  But let's see why this is the case using simple math again.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;400px total width&lt;/li&gt;
&lt;li&gt;12 flex items at width of 50px each = 600px, so there is 200px of "overflow"&lt;/li&gt;
&lt;li&gt;Each flex item: &lt;code&gt;flex-shrink: 1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;12 flex items, so adding the &lt;code&gt;flex-shrink&lt;/code&gt; values up, we get 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 12 units&lt;/li&gt;
&lt;li&gt;200px of overflow / 12 units = 16.66px&lt;/li&gt;
&lt;li&gt;So... each flex item will reduce from an original size of 50px to a size of 50px - 16.66px = 33.34px&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sounds great, but here's the problem...  Some of our items (10, 11, and 12) cannot shrink to 33.34px, which means we are going to have some overflow.  Remember, flex items can shrink, but not more than their inner content.&lt;/p&gt;

&lt;p&gt;Let's back up.  We know for sure that 9 items fit in this container, so let's go with that for now.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/ExNMveb"&gt;flex-grow example #2a&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/ExNMveb?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's see how we can use &lt;code&gt;flex-shrink&lt;/code&gt; to alter how our "overflow" space is allocated to each flex item.  Right now, we have 50px of "overflow" (50px flex items * 9 = 450px - 400px of total flex container space).  We have to allocate that 50px "overflow" out to flex items.  At the moment, each flex item has a &lt;code&gt;flex-shrink&lt;/code&gt; value of &lt;code&gt;1&lt;/code&gt;, which means they will all receive an equal allocation (so long as that doesn't shrink the item smaller than its content).&lt;/p&gt;

&lt;p&gt;What if I wanted the first 3 elements to keep their full size of 50px and let the remaining flex items absorb that 50px "overflow"?  Here's how you do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-shrink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-shrink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-shrink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* No need to set the rest because they default to flex-shrink: 1 */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we have flex items 1-9 with the following &lt;code&gt;flex-shrink&lt;/code&gt; values: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 = 6 "units"&lt;/li&gt;
&lt;li&gt;Total overflow of 50px (50px * 9 = 450px - 400px = 50px)&lt;/li&gt;
&lt;li&gt;1 unit = 50 / 6 = 8.33px&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So in this scenario, flex items 1-3 keep their width of 50px and the remainder are reduced by 8.33px (so long as this is possible based on their inner content width).  Here it is in code:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/LYbazxa"&gt;flex-shrink example #2d&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/LYbazxa?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Look closely, the first three items are 50px wide while the rest are 50px - 8.33px = 41.66px wide.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quick Review
&lt;/h4&gt;

&lt;p&gt;We know that if there is "empty space" in a flex container, &lt;code&gt;flex-grow&lt;/code&gt; determines how flex items will occupy that space.   We also know that if there is "overflow" in a flex container, &lt;code&gt;flex-shrink&lt;/code&gt; will determine how the items will shrink to fit the space.&lt;/p&gt;

&lt;p&gt;The last piece to the puzzle is &lt;code&gt;flex-basis&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  flex-basis
&lt;/h4&gt;

&lt;p&gt;In all of our examples so far, the &lt;code&gt;flex-basis&lt;/code&gt; property has been set to &lt;code&gt;auto&lt;/code&gt;, but there are more values possible.&lt;/p&gt;

&lt;p&gt;Here they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;flex-basis: auto&lt;/code&gt; - looks for &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; properties on element, and if not found, adopts the content width and height&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flex-basis: content&lt;/code&gt; - to avoid a lengthy, unnecessary discussion, think of this as the equivalent to &lt;code&gt;auto&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flex-basis: %, px&lt;/code&gt; - In addition to &lt;code&gt;auto&lt;/code&gt; and &lt;code&gt;content&lt;/code&gt;, it can accept any values that the normal CSS &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; properties can accept.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we change this value from &lt;code&gt;auto&lt;/code&gt; to a specific width or height, the flex items will change size.  In the example below, all the flex items have widths of 50px, but by explicitly defining widths via the &lt;code&gt;flex-basis&lt;/code&gt; property, I can override them.  You'll notice that I've assigned &lt;code&gt;flex-basis&lt;/code&gt; values of 25%, 35%, 15% and 20% for items 1-4 respectively.  These add up to 95%, so you will see a small amount of "empty space" at the far right side of the container.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/poNYWLp"&gt;flex-basis 1&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/poNYWLp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The reason there is empty space is because by default, all the &lt;code&gt;flex-grow&lt;/code&gt; values are set to &lt;code&gt;0&lt;/code&gt;.  If I added &lt;code&gt;flex-grow: 1&lt;/code&gt; to any of the elements, they will no longer respect their width or &lt;code&gt;flex-basis&lt;/code&gt; values and will expand to fill the remaining space.  Let's go ahead and do that with flex item 4.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/oNYVoWL"&gt;flex-basis 2&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/oNYVoWL?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;As you can see, the &lt;code&gt;flex-grow&lt;/code&gt;, &lt;code&gt;flex-shrink&lt;/code&gt;, &lt;code&gt;flex-basis&lt;/code&gt;, and &lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt; properties all compete with each other to assign dimensions to flex items.  The challenge is to know which ones will win in each situation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ordering Flex Items
&lt;/h3&gt;

&lt;p&gt;The last part of Flexbox that I want to cover here today is the &lt;code&gt;order&lt;/code&gt; CSS property.  In any case, the most straightforward way to order HTML elements is to change their order within the HTML itself.  But sometimes, when &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/9-intro-to-responsive-web-design/"&gt;designing responsively&lt;/a&gt;, you may want to order the Flex Items differently based on different screen sizes.  This is where the &lt;code&gt;order&lt;/code&gt; property comes in.&lt;/p&gt;

&lt;p&gt;It is relatively simple.  By placing the &lt;code&gt;order&lt;/code&gt; property on a single flex item, you can specify where it belongs on the &lt;strong&gt;main axis&lt;/strong&gt;.  In the example below, I have set each flex item to 25% width via the &lt;code&gt;flex-basis&lt;/code&gt; property and re-ordered the items with the &lt;code&gt;order&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-basis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-basis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-basis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.flex-item-4&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex-basis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what that looks like (note that the numbers in the boxes indicate the actual HTML order).&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/NWbJwvB"&gt;flex order&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/NWbJwvB?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion and Code Challenge
&lt;/h2&gt;

&lt;p&gt;Getting comfortable using Flexbox takes time.  You need to build things to really grasp what this is all about.  Use the post above along with &lt;a href="https://yoksel.github.io/flex-cheatsheet"&gt;this cheatsheet&lt;/a&gt; as you use Flexbox in your webpages and you will start to recognize how much of an improvement it is over the classic way of creating CSS layouts!  You will also realize that with Flexbox (and in the next lesson, CSS Grid), CSS Frameworks are often not necessary to build beautiful designs on the web.&lt;/p&gt;

&lt;p&gt;To reinforce these skills, I suggest watching &lt;a href="https://youtu.be/n0QmD2i90_c"&gt;this video&lt;/a&gt; where I build the following design with Flexbox!  I'll see you in the video :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09vdiy9stexpyrcsjtlf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09vdiy9stexpyrcsjtlf.jpg" alt="testimonial grid" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Responsive Web Design for Complete Beginners #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Tue, 09 Mar 2021 01:10:18 +0000</pubDate>
      <link>https://dev.to/zachgoll/responsive-web-design-for-complete-beginners-434c</link>
      <guid>https://dev.to/zachgoll/responsive-web-design-for-complete-beginners-434c</guid>
      <description>&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/7-html-crash-course/"&gt;A basic understanding of HTML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/8-css-crash-course/"&gt;A basic understanding of CSS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://youtu.be/l7WZgRg7-sM"&gt;View this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By the end of this lesson, you should &lt;em&gt;what&lt;/em&gt; "responsive web design" is and &lt;em&gt;why&lt;/em&gt; we care so much about it.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://www.youtube.com/watch?v=zwBoEwUD__0"&gt;prior lesson&lt;/a&gt;, we built this pricing component with HTML and CSS:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6s4qc7qnwyte155lht9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6s4qc7qnwyte155lht9.jpg" alt="card desktop preview" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But when we resize this in the browser, it gets cut off...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7527wga0kebpfqged5v.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7527wga0kebpfqged5v.JPG" alt="bad responsive design" width="503" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this lesson, we're going to learn how to fix this design and make it look like this on a mobile device:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80bwgvccnsq58bokzidm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80bwgvccnsq58bokzidm.jpg" alt="mobile pricing card" width="375" height="870"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in future lessons, we will be adding Flexbox and CSS to our toolkit so that we can create these awesome designs!  Let's dive in, we've got a lot to learn!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81u2el9bsdwoor47si5o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81u2el9bsdwoor47si5o.jpg" alt="grid challenge" width="800" height="586"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90pumh9vzet1k81fyqzd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90pumh9vzet1k81fyqzd.jpg" alt="landing page preview" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What we are covering in this lesson
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What is responsive design and why does it matter?&lt;/li&gt;
&lt;li&gt;Mobile-first vs. desktop-first designs&lt;/li&gt;
&lt;li&gt;What are CSS Breakpoints?&lt;/li&gt;
&lt;li&gt;A Responsive Design Checklist&lt;/li&gt;
&lt;li&gt;Learning how to turn our pricing card from the previous challenge into a mobile-responsive design&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;p&gt;This is part of my full-stack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first full-stack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Responsive Web Design?
&lt;/h2&gt;

&lt;p&gt;We call it "responsive" design because our websites and web apps should "respond" to the user changing his/her screen size.  In other words, the user should have a pleasant experience using your website on their iPhone and their massive, 2560 pixel monitor.&lt;/p&gt;

&lt;p&gt;Maybe the best way to visualize what we mean by "responsive design" is to look at a website with poor responsive design.  It's 2021, and thanks to all the website builder tools, most websites meet the minimum standards for responsive design.  For that reason, I made a simple example showing what responsive design is &lt;strong&gt;NOT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ODOH2lNA1GQLd4VfBk/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ODOH2lNA1GQLd4VfBk/giphy.gif" alt="bad responsive design" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the design from above, but "responsive".  It is by no means the most beautiful thing in the world, but it demonstrates what "responsive design" means in a visual way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/LE4ICU8eVexnnH5HvM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/LE4ICU8eVexnnH5HvM/giphy.gif" alt="better responsive design example" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I first started learning to write HTML and CSS, the &lt;strong&gt;last&lt;/strong&gt; thing I wanted to worry about was fitting my web app on multiple screen sizes.  Writing the HTML, CSS, and JavaScript was hard enough on one device!  I'm guessing you feel the same way, and for that reason, I want to start by explaining why I feel the need to include this topic in my full-stack web developer roadmap series.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You should care about responsive design because if you don't, your users will leave and probably not come back&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If your users have to squint to see your website on their iPhone and can't click the links because they are so small, they will get frustrated and they will leave, no matter how good the "content/functionality" of your site is.  &lt;/p&gt;

&lt;p&gt;Okay okay, but Zach, I'm learning to code; not trying to build the perfect software product right?&lt;/p&gt;

&lt;p&gt;I get it.  Sometimes, you need to learn concepts; not waste your time fiddling around with different screen sizes for your apps.  For that reason, I am going to show you the "80/20" guide to responsive design.  Getting your website/app to look good on all devices shouldn't be rocket science.  To help us prove this out, let's look at something called "mobile-first web design".&lt;/p&gt;
&lt;h2&gt;
  
  
  Mobile First vs. Desktop First
&lt;/h2&gt;

&lt;p&gt;When I first heard these terms, I thought I needed to learn some entirely new framework for writing CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;These terms are much simpler than people make them.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When someone says that they prefer mobile-first design, they are literally telling you that they write the CSS code for a mobile device &lt;strong&gt;first&lt;/strong&gt;, and &lt;em&gt;then&lt;/em&gt; write the necessary "breakpoints" (more on this later) and CSS rules to make the same site look good on large screens.&lt;/p&gt;

&lt;p&gt;Given the necessity of functional mobile designs in today's world, it is good to adopt a "mobile-first" mindset from the outset.  Embrace it, and your users will thank you.&lt;/p&gt;
&lt;h3&gt;
  
  
  Design Starts without Code
&lt;/h3&gt;

&lt;p&gt;Here is a concept that took me a while to internalize.  Before you write a single line of code, you should have some sort of visual to look at for your mobile and desktop designs.  At a minimum, you should have &lt;strong&gt;one&lt;/strong&gt; of the following two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Wireframes - simple sketches of your design to illustrate the &lt;em&gt;layout&lt;/em&gt; you want&lt;/li&gt;
&lt;li&gt;Mockups - full designs that depict &lt;em&gt;layout&lt;/em&gt; (how the elements are arranged) and &lt;em&gt;style&lt;/em&gt; (colors, fonts, etc.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A wireframe is meant to be simple.  The quickest way to get started is with some good ole' pencil and paper.  Here is an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffyw5bq2epgq1mbmzr3ek.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffyw5bq2epgq1mbmzr3ek.jpg" alt="wireframe" width="800" height="676"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are wireframing softwares available, but since the goal of wireframing is to get a visual idea out of your head, pencil and paper work well.  If you need to design several website/app views in a much larger project, you probably need a mockup.  This will be a (near) exact replica of what you want your end application to look like.  While there are plenty of tool available for doing this, the easiest way to get started at the time of writing is with &lt;a href="https://www.figma.com/"&gt;Figma&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you don't have a clear visual of what you're trying to create, you won't be able to strategically write your HTML and CSS to fit that design.  In other words, you'll waste a LOT of time.&lt;/p&gt;
&lt;h3&gt;
  
  
  But I can't design well?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;That's fine.  You don't have to.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I don't consider myself a terrible designer, but I've struggled a lot with it and I don't really enjoy it.  The best solution in my situation is simple–hire a great designer to design all your web apps.&lt;/p&gt;

&lt;p&gt;But finding a great designer takes time and it takes money; something that most of us don't have when we're learning to code.&lt;/p&gt;

&lt;p&gt;Our next best option is to leverage existing designs, which is why we are using the Frontend Mentor designs in this course!&lt;/p&gt;

&lt;p&gt;If you enjoy design and are decent at it, you might like to spend some time on this step of the process.  If not, leverage existing designs as much as you can.&lt;/p&gt;
&lt;h3&gt;
  
  
  Can we review?  What is "mobile-first" design again?
&lt;/h3&gt;

&lt;p&gt;Before you write a single line of code, you need a wireframe or a mockup for both your mobile and desktop versions of the app/website.  If you need both, where does the "mobile-first" part come in?&lt;/p&gt;

&lt;p&gt;The "mobile-first" concept enters the picture when we start coding, but before we can talk about it, we need to explore something called a "CSS breakpoint".&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a CSS Breakpoint?
&lt;/h2&gt;

&lt;p&gt;So far in this series, we've left the "logic" of our webpages to JavaScript.  Luckily, CSS has a few built-in ways to add logic to your designs, and one of those is breakpoints.&lt;/p&gt;

&lt;p&gt;If I set a breakpoint at 600 pixels, what does that mean?&lt;/p&gt;

&lt;p&gt;Well, the "viewport" of your webpage (the visible page in the browser) is always going to have a width.  Remember, we can see it using JavaScript?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we can use it with CSS too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-class&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 100vw is equivalent to document.innerWidth */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I set a "breakpoint" at 600 pixels, I can style the elements on the page differently depending on whether the screen size is less than 600 pixels or more than 600 pixels.  The following example isn't necessarily "useful", but it demonstrates this concept well.  We are changing the text color based on the screen size.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/r1C1emOAjdcpPaeQtB/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/r1C1emOAjdcpPaeQtB/giphy.gif" alt="breakpoint example" width="480" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Changing the color of text isn't all that useful, but we can also change the flow of the elements on the page.  This is where media queries start helping us out a lot!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/meWo4ari256OYeReTH/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/meWo4ari256OYeReTH/giphy.gif" alt="breakpoint example 2" width="480" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this simple example, you can imagine how helpful these breakpoints will be for us!&lt;/p&gt;

&lt;h3&gt;
  
  
  Choosing your Breakpoints
&lt;/h3&gt;

&lt;p&gt;Remember, our goal is to design our webpages so that they are easy to interact with on ALL devices.  Each device will have a different default pixel width, but here are some ranges that we can look at.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TVs and High-Resolution Desktops - 2560 pixels&lt;/li&gt;
&lt;li&gt;Laptops - 1024-1440 pixels&lt;/li&gt;
&lt;li&gt;Tablets - 600-800 pixels&lt;/li&gt;
&lt;li&gt;Mobile Devices - 320-480 pixels&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please note, these are not precise ranges; they are just to give you a "ballpark" idea of what we're dealing with.&lt;/p&gt;

&lt;p&gt;So the question becomes... If we have hundreds of different screen sizes that we have to design for, do we need hundreds of CSS breakpoints?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each breakpoint you add to your webpage adds work to your day.  Here are the questions we should be asking when determining what breakpoints to use and how many to use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Will this webpage be used on a mobile device often?&lt;/li&gt;
&lt;li&gt;Is having an intricate mobile, tablet, and desktop design critical?&lt;/li&gt;
&lt;li&gt;Are there breakpoint "standards" we can use?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Usually, the answer to the first question is yes unless the web app has a mobile app.  For example, YouTube doesn't need to break the bank on a mobile-responsive web app because they have mobile apps on both Android and iOS.  Remember, web app !== mobile app.&lt;/p&gt;

&lt;p&gt;In our case, the answer to question #2 is no.  We care mostly about learning concepts here, not optimizing a product.&lt;/p&gt;

&lt;p&gt;The answer to question #3 is yes and no.  Since there are so many different devices out there, it is hard to determine a "standard" for when your web app needs to change layouts.  That said, there are several CSS frameworks out on the market that we can copy breakpoints from.  We won't be diving into CSS frameworks in this full-stack series (reasoning &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/8-css-crash-course/"&gt;explained in prior lesson&lt;/a&gt;), but here's the thing about CSS frameworks–their creators have thought about this stuff a LOT.  Most CSS frameworks come with some sort of layout system, and that layout system is based on the breakpoints that they choose.&lt;/p&gt;

&lt;p&gt;One of the most popular CSS frameworks is Boostrap, and here are &lt;a href="https://getbootstrap.com/docs/5.0/layout/breakpoints/#available-breakpoints"&gt;their CSS breakpoints&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;≥576px&lt;/code&gt; (sm)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;≥768px&lt;/code&gt; (m)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;≥992px&lt;/code&gt; (l)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;≥1200px&lt;/code&gt; (xl)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;≥1400px&lt;/code&gt; (xxl)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do we have to use all six of these?  No.&lt;/p&gt;

&lt;p&gt;Our goal is to learn the basics of responsive design and focus on the code side of things, and therefore, we only need to use 1-2 of these (one design for mobile and tablet, one design for everything larger than those).&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing Breakpoints with CSS
&lt;/h3&gt;

&lt;p&gt;We have been hanging out in theory land this entire post, so let's finally write some code!  Here is the basic "breakpoint" syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* On screen sizes ≥756px, apply these CSS rules */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;/* CSS rules go here */&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we go any further, let's figure out what this &lt;code&gt;@media&lt;/code&gt; syntax means.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media"&gt;Here is the documentation&lt;/a&gt; for it, but in short, this is what we call a CSS &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule"&gt;At-rule&lt;/a&gt;, which tells the CSS code how to behave.  There are &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule#index"&gt;several other "At-rules"&lt;/a&gt;, but &lt;code&gt;@media&lt;/code&gt; is what we're interested in for now.&lt;/p&gt;

&lt;p&gt;It is called a "media" query because this rule allows us to target different types of digital devices.  Let's re-write the same rule from above four different ways.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c"&gt;/* Target all devices */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c"&gt;/* Target paged material (i.e. "print preview" mode) */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c"&gt;/* Target mobile devices, tablets, computer screens (most common) */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;speech&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c"&gt;/* Target speech synthesizers */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following two rules do the same thing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what's going on here?  &lt;/p&gt;

&lt;p&gt;CSS has logical operators just like we learned about with JavaScript.  Remember this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Some code here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator allows us to required multiple "conditions".  With our &lt;code&gt;@media&lt;/code&gt; queries, we may need to target multiple conditions.  For example, we could target only "screens" that are between 400 and 600 pixels with this rule.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; 
  &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; 
  &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
  &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;/* CSS rules here */&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Furthermore, &lt;code&gt;min-width&lt;/code&gt; and &lt;code&gt;max-width&lt;/code&gt; are not the only arguments you can use with these rules.  In the next few lessons, I am going to introduce CSS Grid and Flexbox, which are not supported yet in all browsers.  We could use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@supports"&gt;@supports at-rule&lt;/a&gt; along with a media query to only apply certain styles to browsers that support these frameworks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Only use these rules if the browser supports Flexbox */&lt;/span&gt;
&lt;span class="k"&gt;@supports&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;/* CSS rules here */&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The 80/20 Guide to Media Queries
&lt;/h3&gt;

&lt;p&gt;As you can see, we're getting a little carried away here.  Media queries are not just for setting breakpoints and changing CSS styles on different sized devices.  We can do all sorts of interesting things with them.&lt;/p&gt;

&lt;p&gt;But as I promised you at the beginning of this full-stack developer series, I'm going to show you what's important and what's not.  And right now, this is the only syntax that is important to us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;756px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since our goal is to learn full-stack web development (which spans a TON of topics) we don't have time to care about...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser support&lt;/li&gt;
&lt;li&gt;Media types&lt;/li&gt;
&lt;li&gt;CSS logical operators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may need these at some point, but you'll address it when you get there.&lt;/p&gt;

&lt;p&gt;For now, I want you to learn exactly how to read this stylesheet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;576px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;49%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;992px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the Codepen for this to have as a reference.  If you open it up, you can resize it to see how it works.  A quick explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mobile devices will display 100% width images (i.e. images vertically stacked)&lt;/li&gt;
&lt;li&gt;Tablet devices will display 49% width images (i.e. 2 images in each row).  We can't use 50% because of whitespace.  Once we learn Flexbox and CSS Grid, this won't be a problem for us anymore.&lt;/li&gt;
&lt;li&gt;Desktop devices will display 24% width images (i.e. 4 images in each row).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/dyOqZpQ"&gt;Simple Media Queries&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/dyOqZpQ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Believe it or not, &lt;strong&gt;what we have just written above is considered "mobile-first" CSS&lt;/strong&gt;.  Why?  Because we are writing our breakpoints using the &lt;code&gt;min-width&lt;/code&gt; property.  All the "default" styles at the top will apply to mobile devices, and then subsequent rules in the media query rules will override these default styles.&lt;/p&gt;

&lt;p&gt;Also, remember that &lt;code&gt;576px&lt;/code&gt; and &lt;code&gt;992px&lt;/code&gt; came from the Bootstrap breakpoints we talked about above.&lt;/p&gt;

&lt;p&gt;Here's how this stylesheet is interpreted.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser: "Hey CSS, here's a stylesheet with some breakpoints for you.  The current screen size is 1200px.  What width should the images be?"&lt;/li&gt;
&lt;li&gt;CSS: "Oh hey Browser.  Let me read through this..."&lt;/li&gt;
&lt;li&gt;CSS: "First, I see an image width of 100%.  Let me keep reading though in case there are rules later in the file"&lt;/li&gt;
&lt;li&gt;CSS: "Oh wait!  I see a media query with a CSS rule on images.  Is the current screen of 1200px greater than 576px?  Why yes it is!  Let me replace my image widths to now be 49%"&lt;/li&gt;
&lt;li&gt;CSS: "Okay I'm getting tired, but let me keep reading.  I see one more media query.  Is the current screen of 1200px greater than 992px?  Yep!  Let me replace my image width to now be 24%."&lt;/li&gt;
&lt;li&gt;CSS: "Looks like that's the end of the file.  I'll keep image widths at 24%."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What if we threw a curveball and had the following stylesheet?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;992px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;576px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;49%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how in this stylesheet, the media queries are reversed!  Since the CSS document is read from top to bottom ("cascading"), the &lt;code&gt;min-width: 992px&lt;/code&gt; media query will NEVER get applied.  Since the final media query applies to all devices above 576 pixels, that will also apply to large desktop devices, and since it is last in the stylesheet, it will override the first media query!  In effect, for non-mobile devices, there will be 2 images per row.&lt;/p&gt;

&lt;p&gt;The lesson here?  &lt;strong&gt;The order of your media queries is very important&lt;/strong&gt;.  Here are a few things to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Media queries always go at the &lt;strong&gt;bottom&lt;/strong&gt; of your stylesheet&lt;/li&gt;
&lt;li&gt;If you have multiple &lt;code&gt;min-width&lt;/code&gt; media queries (i.e. "mobile-first"), the largest pixel values go last.&lt;/li&gt;
&lt;li&gt;If you have multiple &lt;code&gt;max-width&lt;/code&gt; media queries (you usually won't because that is considered "desktop-first"), the smallest pixel values go last.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What do I put in the media query blocks?
&lt;/h3&gt;

&lt;p&gt;The answer to this will become more apparent with experience.  The important thing to know is that &lt;em&gt;most&lt;/em&gt; of your CSS styles will go at the top of the file; not within media query blocks.  In other words, you want to style your HTML "mobile-first" and then make small tweaks to larger designs only when necessary (via media queries).&lt;/p&gt;

&lt;p&gt;We will be practicing this throughout the remainder of the series, so don't worry too much just yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Mobile-first" Revisited
&lt;/h2&gt;

&lt;p&gt;In my opinion, the reason mobile-first is a good practice to follow is for two reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HTML is naturally "responsive"&lt;/li&gt;
&lt;li&gt;Most people will visit your website/app on a mobile device at some point (but not vice-versa)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you write more HTML and CSS, you will realize that without CSS, HTML shows up just fine on a mobile device.  It may not look pretty, but it will have readable text and reasonably sized images.&lt;/p&gt;

&lt;p&gt;Poor mobile experiences only happen when you start overriding HTML's natural behavior with CSS.  If you design for desktop-first, there is no guarantee that your website/app will be useable on a mobile device.  If you design mobile-first, your website/app will likely work just fine on larger screens without any modification.&lt;/p&gt;

&lt;p&gt;And once again, "mobile-first" simply means writing breakpoints with &lt;code&gt;min-width&lt;/code&gt; media queries as opposed to &lt;code&gt;max-width&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is "mobile-first":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;576px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;49%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;992px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is "desktop-first":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;992px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;49%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;576px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a subtle difference, but an important one.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Responsive Design Checklist
&lt;/h2&gt;

&lt;p&gt;True to our "80/20" theme, here are the most important things to look for when reviewing your webpages.  If you can put a check-mark by each of these, everyone will be happier.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fluid Layouts&lt;/strong&gt; - Does your content rearrange itself on different devices?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Images&lt;/strong&gt; - Do your images maintain good aspect ratios on all devices?  Are they appropriate sizes on each device?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Text&lt;/strong&gt; - Your text should be a "comfortable" size with "comfortable" spacing on every device.  No hard and fast rules here, but generally, keep your body text around 16 pixels, and no more than 700 pixels wide on any device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Overflow&lt;/strong&gt; - Nothing should overflow the screen (i.e. cut-off images or text)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Full-width mobile content&lt;/strong&gt; - As a general rule of thumb, don't show columns on mobile devices, and make everything 100% width of the screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;General Useability&lt;/strong&gt; - Are your buttons big enough to click on a mobile device?  Are the most important things showing first?  I could get into a long checklist on this one, but just have a friend use your site on a mobile device and desktop device.  They will quickly be able to notice anything that doesn't "feel" right.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A Quick Project
&lt;/h2&gt;

&lt;p&gt;In the next two lessons of this series, we will be wrapping up our lengthy discussion on CSS with Flexbox and CSS Grid.  In addition, we will be doing two projects that will combine everything we've learned.&lt;/p&gt;

&lt;p&gt;For now, I challenge you to turn our HTML/CSS challenge from the prior lesson into a mobile-responsive webpage.  In &lt;a href="https://www.youtube.com/watch?v=zwBoEwUD__0"&gt;this video&lt;/a&gt;, we built this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6s4qc7qnwyte155lht9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6s4qc7qnwyte155lht9.jpg" alt="card desktop preview" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the Codepen that I built it in.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/yLVpLPY"&gt;Pricing Card Code Challenge #fullstackroadmap&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/yLVpLPY?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;When you resize the browser, this design does not "respond".  I want you to refactor the code you wrote so that when looking at this on a mobile device, you see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80bwgvccnsq58bokzidm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80bwgvccnsq58bokzidm.jpg" alt="mobile pricing card" width="375" height="870"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Two Ways to Solve this
&lt;/h3&gt;

&lt;p&gt;When we first built this, we did it "desktop-first".  Because of this, the quickest and simplest way to make it "responsive" is to add CSS to the following media query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;650px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c"&gt;/* Make it responsive with CSS here */&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Currently, our pricing card has a width of 600 pixels, so in order to make it "responsive", we need to change its layout on devices less than 650 pixels (or somewhere around that number–it doesn't have to be exact).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/zg_dev/pen/vYyzpgG"&gt;Here is the solution&lt;/a&gt; to the "desktop-first" approach (hint: it only requires a few lines of CSS, and no changes to the HTML).&lt;/p&gt;

&lt;p&gt;The second way of solving this is by using a "mobile-first" approach.  This will take much longer and will be more challenging because you will need to completely rethink your HTML and CSS.  If you go this route, I suggest the following breakpoint to stay consistent with the Bootstrap breakpoints we have been using throughout this lesson.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;576px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codepen.io/zg_dev/pen/JjbaMGQ"&gt;Here is the solution&lt;/a&gt; using the "mobile-first" approach.&lt;/p&gt;

&lt;p&gt;I mentioned earlier in the post that "mobile-first" designs will save you time and lines of code, but in this particular case, that was not true.  Don't worry though, as your projects get larger and more complex, the "mobile-first" mindset will pay off!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>css</category>
      <category>codepen</category>
    </item>
    <item>
      <title>Lesson 8 - CSS Crash Course for Beginners #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Mon, 01 Mar 2021 15:58:13 +0000</pubDate>
      <link>https://dev.to/zachgoll/lesson-8-css-crash-course-for-beginners-fullstackroadmap-59b1</link>
      <guid>https://dev.to/zachgoll/lesson-8-css-crash-course-for-beginners-fullstackroadmap-59b1</guid>
      <description>&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This tutorial is for the complete beginner.  Here are the required skills:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/7-html-crash-course/"&gt;A basic understanding of HTML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Required for solving the code challenges: &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;lessons 1-7 in this series&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;See this crash course on YouTube:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://youtu.be/hAD58ej0E4o"&gt;Part 1 - CSS Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/gGjJDEEXFv0"&gt;Part 2 - Box Model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/dqaNvIJ4Fyk"&gt;Part 3 - Must Know CSS Properties&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/zwBoEwUD__0"&gt;Part 4 - Pricing Grid Code Challenge&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end of this lesson, you will have built this from scratch (&lt;a href="https://www.frontendmentor.io/challenges/single-price-grid-component-5ce41129d0ff452fec5abbbc/hub/single-price-grid-component-7wZJ4lx_U"&gt;Frontend mentor link&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt75eqwhamskgms8mxpi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt75eqwhamskgms8mxpi.jpg" alt="desktop card preview" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And after a few short lessons on responsive design, CSS Grid, and Flexbox, we will build this (&lt;a href="https://www.frontendmentor.io/challenges/testimonials-grid-section-Nnw6J7Un7/hub/testimonials-grid-section-QuSSjaTVM"&gt;Frontend mentor link&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjf4m88b110sdelr7e6yz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjf4m88b110sdelr7e6yz.jpg" alt="css grid challenge preview" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And finally, we'll bring everything we've learned in this course together to build this (&lt;a href="https://www.frontendmentor.io/challenges/crowdfunding-product-page-7uvcZe7ZR/hub/crowdfunding-product-page-7OC236vqP"&gt;Frontend mentor link&lt;/a&gt;).  No, this is not the final project, but will be pretty exciting to build with our new skills!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq98uueynkpknnxtxj3a0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq98uueynkpknnxtxj3a0.jpg" alt="product landing page" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What we are covering in this lesson
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What is CSS (cascading style sheets)?&lt;/li&gt;
&lt;li&gt;The basics of CSS

&lt;ul&gt;
&lt;li&gt;What is a “selector”?&lt;/li&gt;
&lt;li&gt;What is a CSS “property”?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The “Box Model”

&lt;ul&gt;
&lt;li&gt;Block vs. Inline Elements&lt;/li&gt;
&lt;li&gt;Box Sizing&lt;/li&gt;
&lt;li&gt;Layouts in CSS&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;CSS Units of Measure&lt;/li&gt;
&lt;li&gt;Common CSS Properties

&lt;ul&gt;
&lt;li&gt;Font styling&lt;/li&gt;
&lt;li&gt;Background styling&lt;/li&gt;
&lt;li&gt;Color Codes&lt;/li&gt;
&lt;li&gt;“Shorthand” CSS&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;A four-step system for writing great CSS and HTML&lt;/li&gt;
&lt;li&gt;Code Challenges!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Supplemental Lessons
&lt;/h3&gt;

&lt;p&gt;While these are not part of the core CSS crash course, these are extremely important topics to know.  While building out our designs pictured above, we will be using all three of these and I highly recommend that you watch my tutorials on each of them before attempting the challenges.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Media Queries and Responsive Web Design (coming soon)&lt;/li&gt;
&lt;li&gt;CSS Flexbox (coming soon)&lt;/li&gt;
&lt;li&gt;CSS Grid (coming soon)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What we are NOT covering
&lt;/h3&gt;

&lt;p&gt;Finally, we will &lt;strong&gt;NOT&lt;/strong&gt; be covering...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Graphic design and wireframing&lt;/strong&gt; - These are huge parts of building a web product, but our focus is learning web development skills; not graphic design or user experience design principles.  Designing a visually pleasing and easy to navigate user interface is &lt;strong&gt;critical&lt;/strong&gt; to building a successful app, but you have the rest of your career to learn these.  Furthermore, if you're a mediocre graphic designer like myself, I recommend leveraging designs of the pros (legally of course).  &lt;a href="https://www.frontendmentor.io/challenges"&gt;Frontend Mentor&lt;/a&gt; removes the design step from the equation and allows us to focus on &lt;strong&gt;coding the design&lt;/strong&gt;.  Don't try to mix design with coding.  You'll take 10x as long on your projects.  Design, then code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS Pre-processors (Sass, LESS, PostCSS)&lt;/strong&gt; - These can be useful for large projects and codebases but usually overkill for smaller projects like the ones in this course.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS Frameworks (Bootstrap, Materialize, Tailwind, etc.)&lt;/strong&gt; - CSS frameworks and UI libraries can be extremely helpful, but you need to learn the fundamentals first.  I don't want to lock you into a framework that is popular today but dead tomorrow.  When I was learning, Bootstrap was huge.  Now, Tailwind is popular.  You can always learn these on the fly, so I'm going to teach you the fundamentals and let you educate yourself based on what is required for your future projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;p&gt;This is part of my fullstack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first fullstack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is CSS (Cascading Style Sheets)?
&lt;/h2&gt;

&lt;p&gt;We've already learned the basic concept of CSS.  In the previous lesson, I introduced the "house" analogy, which describes the following:&lt;/p&gt;

&lt;p&gt;When building a house...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML is the &lt;strong&gt;structure&lt;/strong&gt; (i.e. wood, bricks, concrete, foundation)&lt;/li&gt;
&lt;li&gt;CSS is the &lt;strong&gt;style&lt;/strong&gt; (i.e. paint, landscaping)&lt;/li&gt;
&lt;li&gt;JavaScript is the &lt;strong&gt;function&lt;/strong&gt; (i.e. electric, plumbing, heating, water)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first question we have to answer is, what does "cascading" mean?&lt;/p&gt;

&lt;p&gt;When working with CSS, it is possible to define more than one style for a single HTML element.  Because of this, the CSS needs to know &lt;strong&gt;which rule&lt;/strong&gt; to actually apply to it.  When we say "cascading", we are referring to this fact.  &lt;/p&gt;

&lt;p&gt;Let's say I had the following HTML snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's add three CSS rules (I'll explain how these work later):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The question is–what color will "Some text" be?&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://codepen.io/zg_dev/pen/RwoWRaX"&gt;answer is &lt;strong&gt;green&lt;/strong&gt;&lt;/a&gt;, but right now, we don't know enough about CSS to make this determination.  Let's jump in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic CSS Syntax
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://youtu.be/hAD58ej0E4o"&gt;Here is the video version of this section&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So... What is the purpose of CSS?  The &lt;strong&gt;purpose of CSS&lt;/strong&gt; is to "select" an HTML element and apply some type of style to that HTML element.  Here are the two things that CSS can do for you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Change the &lt;strong&gt;layout&lt;/strong&gt; of HTML elements on the page (rows, columns, sections, sizes)&lt;/li&gt;
&lt;li&gt;Change the &lt;strong&gt;style&lt;/strong&gt; of HTML elements on the page (fonts, colors)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the Codepen below, I've demonstrated both layout and style.  To achieve this result, I have used CSS properties that we will be looking at over the next several lessons.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/dyORWWm"&gt;CSS Layout and Style Example&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/dyORWWm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The diagram below shows the relationship between HTML and CSS in addition to the basic structure of both.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb1llhiepeqduc6mwhsmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb1llhiepeqduc6mwhsmt.png" alt="CSS Diagram" width="400" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above, we are using the HTML element's &lt;code&gt;class&lt;/code&gt; property to "select" it, and then applying the &lt;code&gt;color&lt;/code&gt; style to that element.  We have given the &lt;code&gt;color&lt;/code&gt; property a value of &lt;code&gt;#211E1E&lt;/code&gt;, which is a dark grey color.  In effect, we are turning the text dark grey.&lt;/p&gt;

&lt;p&gt;In this example, &lt;code&gt;.some-class&lt;/code&gt; is the "CSS selector", &lt;code&gt;color&lt;/code&gt; is the CSS property, and &lt;code&gt;#211E1E&lt;/code&gt; is the CSS property value (a hex code, which we'll cover later).&lt;/p&gt;

&lt;p&gt;At this point, it is not clear &lt;strong&gt;why&lt;/strong&gt; I'm using these selectors and properties.  For example, why do I have a &lt;code&gt;.&lt;/code&gt; before the class name?  How did I know to use &lt;code&gt;color&lt;/code&gt; to change the text color?  To answer these questions, let's explore a few of the basic ways to "select" an HTML element with CSS.  Don't worry about all the possible properties yet–we'll get there eventually.  For now, I'll try and stick with the &lt;code&gt;color&lt;/code&gt; property, which changes the color of the text of the selected element.&lt;/p&gt;

&lt;h3&gt;
  
  
  The 3 Main CSS Selector Types
&lt;/h3&gt;

&lt;p&gt;There are three primary ways you can "select" an HTML element in order to style it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;By tag&lt;/li&gt;
&lt;li&gt;By class&lt;/li&gt;
&lt;li&gt;By ID&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since we learned about HTML in the prior lesson, these should sound familiar.  Let's take a minute to review anyways.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"first-paragraph"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;First paragraph of document&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can you spot the &lt;strong&gt;tag, class, and id&lt;/strong&gt; here?  Of course!  The tag is &lt;code&gt;p&lt;/code&gt;, the class is &lt;code&gt;main-text&lt;/code&gt;, and the ID is &lt;code&gt;first-paragraph&lt;/code&gt;.  If you remember from the previous lesson, we were able to use these values to "select" HTML elements using JavaScript.  Remember this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Select by tag&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Select by class&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.main-text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Select by ID&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#first-paragraph&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above selects this HTML element in three different ways using JavaScript.  We use the same type of syntax to select this HTML element with CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Oh hey, I'm a CSS comment.  I'm slightly different than HTML and JS comments */&lt;/span&gt;

&lt;span class="c"&gt;/* Select by tag */&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Select by class */&lt;/span&gt;
&lt;span class="nc"&gt;.main-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Select by ID */&lt;/span&gt;
&lt;span class="nf"&gt;#first-paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are all valid ways to select the HTML element from above using CSS.&lt;/p&gt;

&lt;p&gt;For now, I'm going to be using the &lt;code&gt;color&lt;/code&gt; property and value as a placeholder to explain CSS selectors and "cascading" concepts.  This changes the text color of the HTML element.  &lt;strong&gt;We will be walking through all the different CSS properties later in the lesson&lt;/strong&gt;, but we're not quite ready.&lt;/p&gt;

&lt;p&gt;Here is a useful little cheat sheet that I created to help you remember these three most common CSS selector types.  The property &lt;code&gt;color: green&lt;/code&gt; is not important here.  This could be any CSS property.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmhcp8za2sdnqmkr33dl9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmhcp8za2sdnqmkr33dl9.jpg" alt="css selector types" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Combinators
&lt;/h3&gt;

&lt;p&gt;The three methods that I wrote above are the "textbook" ways to select and style an HTML element.  But we are on lesson 8 of our series and by now, you have probably caught on to the fact that in web development, there are ALWAYS more ways to do things.  The same holds true in this scenario.&lt;/p&gt;

&lt;p&gt;With CSS, there are "combinators" that allow us to "combine" our selectors to identify an HTML element.  &lt;strong&gt;Many times, these can be avoided by placing an ID or class attribute on an element, but you should still be familiar with them&lt;/strong&gt;.  Here's what we're dealing with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Descendant selectors&lt;/li&gt;
&lt;li&gt;Child selectors&lt;/li&gt;
&lt;li&gt;Sibling selectors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hmmm... This sounds familiar, doesn't it...&lt;/p&gt;

&lt;p&gt;Do you remember this image from the prior lesson on HTML?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzk54v4v7u88g9m7hsslm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzk54v4v7u88g9m7hsslm.jpg" alt="dom tree visual" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you remember how we talked about an HTML document being structured like a big happy family of grandparents, parents, children, and siblings?  Well lucky for us, we can leverage that concept once again here.&lt;/p&gt;

&lt;p&gt;Let's see how we can combine some CSS selectors to identify various elements in this HTML document.  Here it is again in case you can't see it from the photo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Site Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Article Heading&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text in the article&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some more text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Site created by Zach&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Selecting descendants
&lt;/h4&gt;

&lt;p&gt;Let's say that we wanted to put a CSS style on every &lt;code&gt;li&lt;/code&gt; element that exists in the &lt;code&gt;&amp;lt;div class="main-body"&amp;gt;&lt;/code&gt; element.  How would we do this?&lt;/p&gt;

&lt;p&gt;Why not something like this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congrats!  All your &lt;code&gt;li&lt;/code&gt; elements will have green text.  Time to call it a day and have a beer.&lt;/p&gt;

&lt;p&gt;Not so fast...&lt;/p&gt;

&lt;p&gt;What happens if we put another list inside the &lt;code&gt;&amp;lt;div class="footer"&amp;gt;&lt;/code&gt; container?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Site Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Article Heading&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text in the article&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some more text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Site created by Zach&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Footer link 1&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Footer link 2&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Footer link 3&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In reality, it is very common to see lists appear in a footer like this, but they are often styled differently than lists in the main body of the HTML.  If we used the selector from above, even our footer list items will have green text, which we probably don't want!&lt;/p&gt;

&lt;p&gt;Let's come up with a better solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Select all li elements that exist inside the element with a class of .main-body */&lt;/span&gt;
&lt;span class="nc"&gt;.main-body&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With CSS, we can combine selectors separated by spaces to identify descendants of elements.  No matter how many additional HTML elements we add to the &lt;code&gt;.main-body&lt;/code&gt; div, they will all inherit this style.  To drill this point home further, let's look at some different HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nf"&gt;#main&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using the "descendant selector" above, we can target all the &lt;code&gt;li&lt;/code&gt; tags at &lt;strong&gt;multiple levels&lt;/strong&gt;, so long as they exist &lt;em&gt;below&lt;/em&gt; the level of our "pre-selector".  In this case, the first selector, &lt;code&gt;#main&lt;/code&gt; is the "pre-selector" and the second selector, &lt;code&gt;li&lt;/code&gt; is the actual element(s) you are targeting for that style.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/OJbyKVp"&gt;Selecting Descendants in CSS&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/OJbyKVp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Selecting Children
&lt;/h4&gt;

&lt;p&gt;Sometimes, you only need to target the children of a specific HTML element for styles.  Let's say you had the following HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;first paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;second paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;third paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;fourth paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we used the CSS selector &lt;code&gt;#main p&lt;/code&gt;, we would be able to style all of the &lt;code&gt;p&lt;/code&gt; elements in this HTML.  But we can use the following syntax to select only the direct children of &lt;code&gt;#main&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nf"&gt;#main&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first, second, and third paragraphs will have blue text while the fourth will have the default text color.&lt;/p&gt;

&lt;p&gt;
  &lt;span&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/yLVYmNE"&gt;
  Selecting Children in CSS&lt;/a&gt; by Zach  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;)
  on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/span&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Selecting Siblings
&lt;/h4&gt;

&lt;p&gt;The last type of combinator you can use is a sibling selector, but I think it is important to disclose–&lt;strong&gt;I NEVER use these&lt;/strong&gt;.  Others may feel differently about this, but in the five years I've been writing CSS, I have never come across a compelling case for using these selectors.  Drop a comment or hit me up on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; if you come up with a good reason to use these.&lt;/p&gt;

&lt;p&gt;But of course, I can't just make a bold statement like that and expect that you trust me.  Let me show you what I mean here.&lt;/p&gt;

&lt;p&gt;Let's say you had this HTML document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;first paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;second paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;third paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;fourth paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;fifth paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;sixth paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for some odd reason, you only want to style the paragraph elements immediately following the lists (first and fourth paragraphs).  Here's how you could do that with a sibling selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/oNYjKjg"&gt;Selecting Siblings in CSS&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/oNYjKjg?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This will look through the entire HTML document and look for all &lt;code&gt;p&lt;/code&gt; elements that immediately follow a &lt;code&gt;ul&lt;/code&gt; element (aka "adjacent sibling").  And if you wanted to target &lt;strong&gt;all&lt;/strong&gt; of the siblings to &lt;code&gt;ul&lt;/code&gt; elements, you just change your CSS to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my opinion, the &lt;code&gt;~&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; combinators aren't necessary.  If you find yourself in this situation, do the following.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the HTML element you want to target&lt;/li&gt;
&lt;li&gt;Add a class or ID to that element&lt;/li&gt;
&lt;li&gt;Style using a class or ID selector&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sure, it's some extra lines of code, but it is easier to follow (and your future self will thank you for writing easy-to-read code).&lt;/p&gt;

&lt;h3&gt;
  
  
  Other ways to select HTML elements with CSS?
&lt;/h3&gt;

&lt;p&gt;There are other ways to select an HTML element with CSS.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"regular-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;some text here&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"regular-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;some text here&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"regular-text"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you just used &lt;code&gt;.regular-text&lt;/code&gt; to select the elements, you would be styling both the &lt;code&gt;p&lt;/code&gt; and &lt;code&gt;div&lt;/code&gt; elements.  You can specify that you only want the &lt;code&gt;p&lt;/code&gt; elements with a class of &lt;code&gt;.regular-text&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The likelihood of a situation like this coming up?  Very low.  Therefore, I won't be spending time explaining all these nuanced ways of using CSS selectors.  You can look them up as you need them.&lt;/p&gt;

&lt;p&gt;Remember, this crash course and full-stack developer series is about getting you acquainted with the &lt;strong&gt;most important&lt;/strong&gt; concepts.  And 95% of the time, you'll never need anything more than what we've talked about so far.  Feel free to dig through some advanced CSS tutorials on your own, but &lt;strong&gt;at this stage of your journey&lt;/strong&gt;, I believe it is a waste of your time to do so.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selecting multiple HTML elements with CSS
&lt;/h2&gt;

&lt;p&gt;To this point, we've only selected one HTML "group" at a time (one selector can target multiple elements).  In certain cases, you might want to apply a few "common" styles to several elements and then add additional styles individually.  Let's say you had the following HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Box 1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Box 2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We haven't talked about CSS properties yet (so don't worry about how these work now), but let's say that we wanted to make both of these boxes the same width and height, but style their borders and text colors separately.  Here is the &lt;strong&gt;inefficient way&lt;/strong&gt; to do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wouldn't it be nice if we could assign the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; properties one time rather than writing for each element?  Good news, we can!  Here's how I would write this CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By separating each selector using a comma, we can select &lt;strong&gt;multiple HTML "groups"&lt;/strong&gt; at the same time.  In the example above, we are applying the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; properties to &lt;em&gt;both&lt;/em&gt; selectors and then individually applying &lt;code&gt;border&lt;/code&gt; and &lt;code&gt;color&lt;/code&gt; (text color) styles to each.  &lt;/p&gt;

&lt;p&gt;We haven't talked a lot about software engineering "best practices", but what we did here was "refactor" our previous code to adhere to "DRY" (don't repeat yourself) principles.&lt;/p&gt;

&lt;p&gt;Here's the Codepen for this.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/gOLxYJJ"&gt;Multiple Selectors at once with CSS&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/gOLxYJJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Multiple Classes on a Single HTML Element
&lt;/h3&gt;

&lt;p&gt;In the example we just looked at, we have two classes and are defining "shared styles" for them.  We could achieve this same result another way!  Take a look.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/yLVoqYa"&gt;Multiple Classes on HTML&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/yLVoqYa?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The change that I made is subtle.  All I did was add another class to the HTML–make sure you add a space between classes in the &lt;code&gt;class&lt;/code&gt; HTML attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box-1 box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Box 1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box-2 box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Box 2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of having two classes, &lt;code&gt;box-1&lt;/code&gt; and &lt;code&gt;box-2&lt;/code&gt;, we now have three.  We can use the &lt;code&gt;box&lt;/code&gt; class to define our shared styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then use our individual classes for unique styles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two methods, same solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pseudo Classes/Elements
&lt;/h3&gt;

&lt;p&gt;In addition to being able to select multiple CSS groups at once, we can also use something called a "pseudo" class/element.  We will NOT be talking in detail about this, but you need to know it exists for when you do come across it in the future.&lt;/p&gt;

&lt;p&gt;Here is the one of the most common occurrences of this concept.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Hover me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding &lt;code&gt;:hover&lt;/code&gt; directly after the &lt;code&gt;button&lt;/code&gt; selector, we are saying, "when the mouse hovers over this button, I want to apply the following CSS styles to it".&lt;/p&gt;

&lt;p&gt;Like I said, we will not be covering this in detail here.  &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements#user-action_pseudo_classes"&gt;Here is some documentation on pseudo elements and classes&lt;/a&gt; that you can read if you are curious.&lt;/p&gt;

&lt;p&gt;Here is the example above in action.  Hover your mouse over the button to see it work!&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/MWbvWym"&gt;MWbvWym&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/MWbvWym?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiple Selectors vs. Nested Selectors
&lt;/h3&gt;

&lt;p&gt;In the previous example, we saw this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the section prior to that, we saw things like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They look awfully similar don't they?  As you read and write CSS, be conscious of this difference.  In the first case, you're saying "I want to apply these styles to all HTML elements that have a class of box-1 OR box-2".  In the second case, you're saying "I want to apply these styles to all p elements that exist inside elements with a class of box-1".&lt;/p&gt;

&lt;p&gt;The difference is subtle, but important.  Speaking of this difference...&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Talk about CSS Specificity
&lt;/h2&gt;

&lt;p&gt;The "cascading" concept in CSS (aka "specificity") is super important for a beginner to understand.&lt;/p&gt;

&lt;p&gt;Being able to select HTML elements is part one of the battle.  The second part is figuring out &lt;strong&gt;which styles apply&lt;/strong&gt; to the given element.  This is not hard when there is only one CSS style per HTML element, but oftentimes, there are several styles competing against each other in a CSS battle.  To demonstrate, let's look at some HTML that has many ways to select each element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"first-paragraph"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;First paragraph of document&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's say our goal was to change the text color of our &lt;code&gt;p&lt;/code&gt; element.  We could do that in &lt;strong&gt;several different ways&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Hey, I'm a CSS comment again. */&lt;/span&gt;

&lt;span class="c"&gt;/* Everything below does the SAME THING */&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#first-paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nc"&gt;.main-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nf"&gt;#first-paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="nc"&gt;.main-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="nf"&gt;#first-paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;#first-paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-container&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;.main-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Yep, I know.  Not what you wanted to see.  And it gets worse...&lt;/p&gt;

&lt;p&gt;If you were to write all of these lines of CSS in the same file, they would all be competing with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"But why would you ever put multiple styles in the same CSS file?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are the only developer writing the styles for your HTML, then you probably wouldn't.  But in many cases, a website or web app will have &lt;strong&gt;multiple stylesheets&lt;/strong&gt;, and some of those will be externally generated.  In other words, you may want to take a pre-existing website theme and apply your own custom styles to it.  In this case, you will be writing competing styles to the ones that were already defined.&lt;/p&gt;

&lt;p&gt;And in this case, you need to know &lt;strong&gt;which style declarations take precedence&lt;/strong&gt; over one another.&lt;/p&gt;

&lt;p&gt;There are two dimensions we must think about here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Location of the CSS selector in the file&lt;/li&gt;
&lt;li&gt;Specificity of the CSS selector&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Location of the CSS Selector in the File
&lt;/h3&gt;

&lt;p&gt;Let's start easy.  Say we had the following HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we had the following CSS file, what color will the text be?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have been following along with this series, you might be thinking, "That's not valid CSS! You've already declared &lt;code&gt;p&lt;/code&gt;, you can't do it again!".&lt;/p&gt;

&lt;p&gt;Good logic, but it is indeed valid CSS.  Unlike JavaScript, you &lt;strong&gt;can&lt;/strong&gt; declare the same CSS rule twice in the same file.  Knowing this fact, which style takes precedence here?&lt;/p&gt;

&lt;p&gt;The text will be &lt;strong&gt;green&lt;/strong&gt; because that is the &lt;strong&gt;last rule&lt;/strong&gt; in the file.  CSS will always give the final rule precedence &lt;strong&gt;assuming the selectors have the same level of "specificity"&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Specificity of the CSS Selector
&lt;/h3&gt;

&lt;p&gt;Let's modify the example from above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What color will the text be?  The answer is &lt;strong&gt;red&lt;/strong&gt;.  In this case, even though our &lt;code&gt;color: green&lt;/code&gt; style came &lt;strong&gt;last in the file&lt;/strong&gt;, it doesn't matter because selecting an HTML element by its class is "more specific" than selecting by its tag.&lt;/p&gt;

&lt;p&gt;Here is the continuum of CSS selector "importance":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyvpwbx389in5mlsdkj87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyvpwbx389in5mlsdkj87.png" alt="CSS selector importance" width="400" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In other words, if given the choice of the following three selectors, the text color will be set to green no matter which order you place the rules in because it is the "most specific".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nf"&gt;#first-paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.main-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Easy enough, but this "specificity" business gets a little confusing when we start talking about something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;paragraph text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nc"&gt;.my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What color will the text be?  The answer is &lt;strong&gt;red&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When we look at a selector like &lt;code&gt;div .my-text&lt;/code&gt;, it is basically saying, "find me all elements with a class name &lt;code&gt;my-text&lt;/code&gt; that are descendants to &lt;code&gt;div&lt;/code&gt; elements".  Then we have to ask ourselves... Does the first paragraph have a class of &lt;code&gt;my-text&lt;/code&gt; AND a &lt;code&gt;div&lt;/code&gt; ancestor (could be parent, grandparent, great-grandparent, etc.)?  The answer is yes, so the paragraph text will be &lt;strong&gt;red&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/XWNmNGe"&gt;Which style takes precedence?&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/XWNmNGe?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In summary, even though the second CSS rule above is at the end of the file, that doesn't mean it will apply to all elements.&lt;/p&gt;

&lt;p&gt;After reading the last couple of paragraphs, you might be thinking that this is awfully complicated.  To help us out, let's look at &lt;strong&gt;two ways&lt;/strong&gt; that you can always use to determine which CSS rule applies to each HTML element.  Here they are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test it out (my favorite method)&lt;/li&gt;
&lt;li&gt;Calculate it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The easiest way to figure it out is to put together an example in Codepen and see which one takes precedence (as we did above).&lt;/p&gt;

&lt;p&gt;The second way is to actually calculate the "specificity" of a CSS rule.  Here's how you do that.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Count the number of ID selectors in the rule&lt;/li&gt;
&lt;li&gt;Count the number of class selectors in the rule&lt;/li&gt;
&lt;li&gt;Count the number of tag selectors in the rule&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Combine the count from steps 1-3 in order, and you've got your "specificity" value.&lt;/p&gt;

&lt;p&gt;Let's do that for our two rules from above.  See the comments for the calculation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* 
  Number of ID selectors - 0
  Number of class selectors - 1
  Number of tag selectors - 1

  Total "Specificity" - 011
*/&lt;/span&gt;
&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nc"&gt;.my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* 
  Number of ID selectors - 0
  Number of class selectors - 1
  Number of tag selectors - 0

  Total "Specificity" - 010
*/&lt;/span&gt;
&lt;span class="nc"&gt;.my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the first selector is &lt;em&gt;more specific&lt;/em&gt; than the second, and therefore will always take precedence (unless it simply does not apply to the HTML element like we saw in the second paragraph from our example above).&lt;/p&gt;

&lt;p&gt;Let's look at one last example to really nail this concept.  Here's the HTML and CSS with the specificity calculation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-container"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"container-id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"text-id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of the rules below select the same &lt;code&gt;p&lt;/code&gt; element above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* 
  Number of ID selectors - 0
  Number of class selectors - 2
  Number of tag selectors - 0

  Total "Specificity" - 020
*/&lt;/span&gt;
&lt;span class="nc"&gt;.my-container&lt;/span&gt; &lt;span class="nc"&gt;.my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* 
  Number of ID selectors - 2
  Number of class selectors - 0
  Number of tag selectors - 0

  Total "Specificity" - 200
*/&lt;/span&gt;
&lt;span class="nf"&gt;#container-id&lt;/span&gt; &lt;span class="nf"&gt;#text-id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* 
  Number of ID selectors - 1
  Number of class selectors - 0
  Number of tag selectors - 1

  Total "Specificity" - 101
*/&lt;/span&gt;
&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="nf"&gt;#text-id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* 
  Number of ID selectors - 1
  Number of class selectors - 0
  Number of tag selectors - 0

  Total "Specificity" - 100
*/&lt;/span&gt;
&lt;span class="nf"&gt;#text-id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* 
  Number of ID selectors - 0
  Number of class selectors - 0
  Number of tag selectors - 1

  Total "Specificity" - 001
*/&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;purple&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The text color will be &lt;strong&gt;orange&lt;/strong&gt; because the total specificity of that selector is the greatest.  Once again, you can always just test it out like I did below!&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/MWbapYP"&gt;Which style takes precedence? v2&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/MWbapYP?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Inline HTML Styles
&lt;/h3&gt;

&lt;p&gt;The last thing we have to talk about are inline styles.  They look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"color: red; padding: 1px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you apply an inline style, it will take precedence over all other styles, but it is usually not recommended because too many of these will really clutter up your HTML!  Some CSS frameworks implement inline styles like this, but that is a debate and topic for another day.  For now, just keep these to a minimum.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/zg_dev/pen/rNWGazo"&gt;Here is a Codepen example&lt;/a&gt; that shows how an inline style can override a style applied with an ID selector.&lt;/p&gt;

&lt;h3&gt;
  
  
  The !important keyword
&lt;/h3&gt;

&lt;p&gt;What if I told you that by writing a single word, you can override all the CSS "specificity rules" (including inline styles)?&lt;/p&gt;

&lt;p&gt;If you write &lt;code&gt;!important&lt;/code&gt; at the end of a CSS property, it will take precedence over every other rule.  Here's an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While the second selector has more specificity, the text will be &lt;strong&gt;red&lt;/strong&gt; because we have added &lt;code&gt;!important&lt;/code&gt; to the end of the property value.  This can be done on a property-by-property basis.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#my-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the color will be red but the font size will be &lt;code&gt;16px&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let's have a little chat&lt;/strong&gt; about this &lt;code&gt;!important&lt;/code&gt; keyword.  While it does provide you with an easy way to get a CSS style working without having to think much, it is &lt;strong&gt;usually a bad practice&lt;/strong&gt;.  There is no definitive guideline as to when this is acceptable to use, but here is a good rule of thumb.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use !important if doing so is the ONLY viable method for styling an element&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This could occur if you are trying to override styles applied from an &lt;strong&gt;external stylesheet&lt;/strong&gt; (CSS frameworks, UI libraries, etc.).&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a CSS Property?
&lt;/h2&gt;

&lt;p&gt;As I introduced at the beginning of this lesson, CSS allows us to achieve two primary objectives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Styling HTML elements&lt;/li&gt;
&lt;li&gt;Positioning HTML elements (layout)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What if I wanted to create an HTML element that has a blue background, is a perfect square, has a black border, and has some large white text centered in the middle?  I can do this with basic CSS properties.&lt;/p&gt;

&lt;p&gt;The HTML for this is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Some Text&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CSS is the tricky part.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;navy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, I've used a variety of properties to achieve this result.  From &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, and &lt;code&gt;border&lt;/code&gt; to &lt;code&gt;background-color&lt;/code&gt;, &lt;code&gt;color&lt;/code&gt;, and &lt;code&gt;text-align&lt;/code&gt;, combining these CSS properties together helps us achieve the intended result.&lt;/p&gt;

&lt;p&gt;Here is the live version of this example.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/qBqjerE"&gt;CSS properties example&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/qBqjerE?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I know what CSS properties to use?
&lt;/h3&gt;

&lt;p&gt;Great question.&lt;/p&gt;

&lt;p&gt;I don't have a great answer.&lt;/p&gt;

&lt;p&gt;The truth is, knowing what properties to use is largely a matter of time combined with lots of experience.  Studying all the properties at once won't help you.  Making flash-cards might help a little, but I wouldn't recommend it.&lt;/p&gt;

&lt;p&gt;As we dive into the Box Model and some common CSS properties, try to focus on concepts; not memorization.  After all, you've always got &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference#index"&gt;the CSS documentation&lt;/a&gt; if you forget what something does.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Box Model in CSS?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://youtu.be/gGjJDEEXFv0"&gt;Here is the video version of this section&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similar to the Document Object Model (DOM) that we explored in the prior lesson, the Box Model can be explained simply, or we can get into tons of nuance.&lt;/p&gt;

&lt;p&gt;It is best described visually via the Firefox Developer Tools (we talked a lot about these in prior lessons).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0ta549fm7xk6bb2qqqz.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0ta549fm7xk6bb2qqqz.JPG" alt="box model calculations" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is saying that our &lt;code&gt;p&lt;/code&gt; element has content dimensions of 667 pixels x 18 pixels, has 20 pixels of padding on all four sides, has a 5 pixel border, and has 20 pixels of margin on all four sides.&lt;/p&gt;

&lt;p&gt;The Box Model attempts to describe how much "space" an element takes up on the page.  The following properties influence that "space" that the element occupies.  I suggest skimming through their documentation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/width"&gt;Width&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/height"&gt;Height&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/padding"&gt;Padding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/border"&gt;Border&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin"&gt;Margin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But these are not the only properties that come into play when we talk about the Box Model.  It is often difficult to introduce this model to beginners because there are several combinations of properties that will completely change the "rules of the game".&lt;/p&gt;

&lt;p&gt;To better explain these "rules", I have created an interactive Codepen that we will be using to better understand the Box Model and all of its nuances.  &lt;strong&gt;Keep this open in another tab while you read the following sections so that you can see in real-time what I am talking about.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/zYodJYM"&gt;Building the Box Model 1&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/zYodJYM?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Element Display Types
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;display&lt;/code&gt; CSS property is arguably the most diverse CSS property there is.&lt;/p&gt;

&lt;p&gt;Here are the possible values you can set for it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;display: none&lt;/code&gt; - Hides the element from the page&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;display: block&lt;/code&gt; - The default display type for &lt;em&gt;most&lt;/em&gt; HTML elements&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;display: inline&lt;/code&gt; - The default display type for &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;, &lt;code&gt;img&lt;/code&gt;, &lt;code&gt;button&lt;/code&gt;, &lt;code&gt;input&lt;/code&gt;, and &lt;a href="https://www.w3schools.com/html/html_blocks.asp"&gt;several other HTML elements&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;display: inline-block&lt;/code&gt; - A mix between &lt;code&gt;block&lt;/code&gt; and &lt;code&gt;inline&lt;/code&gt; (more on this in a minute)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;display: flex&lt;/code&gt; - Enables the Flexbox framework (out of scope for this tutorial)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;display: grid&lt;/code&gt; - Enables CSS Grid framework (also out of scope)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;display: none&lt;/code&gt; value is easy to grasp.  Open up the Codepen from above and change the "Display Type" dropdown to "none".  The orange box will disappear.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;block&lt;/code&gt;, &lt;code&gt;inline&lt;/code&gt;, and &lt;code&gt;inline-block&lt;/code&gt; properties require a bit of an explanation.  Let's jump in.&lt;/p&gt;

&lt;h4&gt;
  
  
  Block vs. Inline Elements
&lt;/h4&gt;

&lt;p&gt;Most elements will have &lt;code&gt;display: block&lt;/code&gt; as their default state.  Open up the Codepen example from above and reset all the values.&lt;/p&gt;

&lt;p&gt;By default, it has a "block" display type.  This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The orange paragraph element will occupy 100% width of its container because we have not explicitly set a height or width (they are both set to auto)&lt;/li&gt;
&lt;li&gt;The orange paragraph is on its own line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, set the "Content Width" to 400px and "Content Height" to 200px using the dropdowns.  The orange paragraph element should change sizes.&lt;/p&gt;

&lt;p&gt;Reset all properties.&lt;/p&gt;

&lt;p&gt;Now change "Display Type" to "inline".  You should see the orange paragraph element jump up to the same line as the green text that was formerly above it.  With an "inline" element, the following behavior happens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The element will only occupy the height and width of the content within it.  In this case, that content is the text, "Some Content".&lt;/li&gt;
&lt;li&gt;The element will not break on a new line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, change the height and width properties using the dropdown again.  Nothing should happen.  That is because when an element is "inline", it does not respect its width and height properties.&lt;/p&gt;

&lt;p&gt;Without resetting anything, change the display type to "inline-block".  What happens?&lt;/p&gt;

&lt;p&gt;The display property &lt;code&gt;inline-block&lt;/code&gt; is the same as &lt;code&gt;inline&lt;/code&gt; &lt;em&gt;except&lt;/em&gt; that it respects its width and height properties.&lt;/p&gt;

&lt;h3&gt;
  
  
  Box Model Variations
&lt;/h3&gt;

&lt;p&gt;Another property that will change the "rules of the game" is the &lt;code&gt;box-type&lt;/code&gt; CSS property.  It does not affect the &lt;em&gt;flow&lt;/em&gt; of the elements on the page like &lt;code&gt;display&lt;/code&gt; does, but it affects the calculation of how much space an element occupies.  Here are the two values.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;box-type: content-box&lt;/code&gt; - this is the default value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;box-type: border-box&lt;/code&gt; - as you will see, this is easier to grasp and often preferred among developers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To see this in action, open up the Codepen from above again, reset everything, and then select the following options.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the content width to 400px&lt;/li&gt;
&lt;li&gt;Set the content height to 200px&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, toggle between the two "Box Type" dropdown options.  Notice how the size of the orange paragraph element changes by a small amount?&lt;/p&gt;

&lt;p&gt;To make this more noticeable, change the "Padding" option to 20px.  Now, toggle the box type again.  Now, you should see large changes in size.  This is because when you are using the value &lt;code&gt;border-box&lt;/code&gt;, the total size of the element will be equal to its height and width.  When using a value of &lt;code&gt;content-box&lt;/code&gt; (the default), the size of your element is the summation of its dimensions, padding, and border.&lt;/p&gt;

&lt;p&gt;Let's look at that screenshot from earlier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0ta549fm7xk6bb2qqqz.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0ta549fm7xk6bb2qqqz.JPG" alt="box model calculations" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, we have the following "specs".&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Element width of 667 pixels&lt;/li&gt;
&lt;li&gt;Element height of 18 pixels&lt;/li&gt;
&lt;li&gt;Padding of 20 pixels (all sides)&lt;/li&gt;
&lt;li&gt;A 5-pixel border on all sides&lt;/li&gt;
&lt;li&gt;Margin of 20 pixels (all sides)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With &lt;code&gt;box-type: content-box&lt;/code&gt;, the total height of this element is 18 + 20 + 20 + 5 + 5 pixels, or 68 pixels.  Here, we add the element height, bottom padding, top padding, bottom border, and top border.  Notice that we did NOT include the margin.  Margin &lt;em&gt;surrounds&lt;/em&gt; the element, but is not &lt;em&gt;part of&lt;/em&gt; the element.  We could also calculate the width as 667 (width) + 20 (left padding) + 20 (right padding) + 5 (left border) + 5 (right border), to get 717 pixels.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;box-type: border-box&lt;/code&gt;, the calculation is much easier.  The total "space" occupied by the element is its width and height.  If you add padding or a border, the size of them will reduce the &lt;em&gt;content&lt;/em&gt; area of the element, but not the total space occupied by the element.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;border-box&lt;/code&gt; type is a bit simpler to understand and makes your job quite a bit easier when trying to fit elements inside parent containers.  In the demo below, look out for the following things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The orange background with "Parent Container" text is an image and is there to help you visualize the dimensions of the parent container.&lt;/li&gt;
&lt;li&gt;The child container has no background color, but has a 5px black border&lt;/li&gt;
&lt;li&gt;Notice how in the first example (content-box), the child is breaking out of the parent container despite being the same exact dimensions.  This is because it has a 5px border, which &lt;em&gt;adds&lt;/em&gt; space to it.  In the second example, this 5px border doesn't cause any problems because it simply reduces the total inner content dimensions, not the outer dimensions.&lt;/li&gt;
&lt;li&gt;When you toggle the padding for both, you'll notice that in the first case, it further expands the size of the child element; breaking it even further out of its parent container.  In the second example, once again, the child is contained within the parent container.  Padding is added, but it doesn't change the total dimensions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/dyOzqvo"&gt;Content vs. Border Box&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/dyOzqvo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Because this property makes our lives so much easier, in many CSS stylesheets, you may see the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;*,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:before&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inherit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a portion of what we call a "CSS reset".  The goal of this is to make every element on your webpage have &lt;code&gt;border-box&lt;/code&gt; box sizing.  The &lt;code&gt;*&lt;/code&gt; selectors target all elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Box Model Review
&lt;/h3&gt;

&lt;p&gt;One could argue that the Box Model encompasses everything we do in CSS.  The main takeaways that I want you to have are these.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Box Model describes how much "space" an HTML element occupies on a webpage&lt;/li&gt;
&lt;li&gt;This "space" is heavily influenced by the &lt;code&gt;box-sizing&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;The "space" and layout is heavily influenced by the &lt;code&gt;display&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;The most important components of the Box Model are height, width, padding, border, and margin&lt;/li&gt;
&lt;li&gt;All other CSS properties are supplementary to this Box Model concept&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Layout Properties
&lt;/h2&gt;

&lt;p&gt;This section deserves an entire lesson on its own.  Positioning HTML elements skillfully on a webpage is not a straightforward topic because there are so many different ways to approach it.  You can use margins, floats, and display properties to position elements.  You can use Flexbox.  You can use CSS Grid.  And finally, you can use a CSS framework to help you with this.&lt;/p&gt;

&lt;p&gt;Rather than trying to cram a large topic into an impossibly small section, I want to draw your attention to three CSS properties that you will spend a lot of time with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;position&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;display&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;float&lt;/code&gt; - with the introduction of Flexbox and CSS Grid, you probably won't ever have to use this, but you may see it in someone's code and therefore we need to cover it&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Position
&lt;/h3&gt;

&lt;p&gt;There are five possible values for the &lt;code&gt;position&lt;/code&gt; property &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position"&gt;as shown in its documentation&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;static&lt;/code&gt; - the default value (most common)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;absolute&lt;/code&gt; - Removes an element from the content flow and positions it "absolutely" relative to the nearest parent element with a position of &lt;code&gt;relative&lt;/code&gt;.  If an "absolute" element has no parent with a "relative" position, it will be positioned relative to the viewport (same as the "fixed" position below).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;relative&lt;/code&gt; - Activates the &lt;code&gt;z-index&lt;/code&gt; property.  Allows content to be positioned in relation to itself, and is often used in conjunction with the &lt;code&gt;absolute&lt;/code&gt; property value above.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fixed&lt;/code&gt; - Removes an element from the content flow and occupies no "space" (often used for navigation bars).  The element will now be positioned relative to the viewport.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sticky&lt;/code&gt; - similar to &lt;code&gt;fixed&lt;/code&gt;, and is not fully supported yet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since &lt;code&gt;static&lt;/code&gt; is the default and &lt;code&gt;sticky&lt;/code&gt; isn't commonly used yet, we'll focus in on &lt;code&gt;absolute&lt;/code&gt;, &lt;code&gt;relative&lt;/code&gt;, and &lt;code&gt;fixed&lt;/code&gt;.  I will not be explaining these in detail, but here is an example I created that showcases how they work.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/zYodwKq"&gt;Position Property CSS&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/zYodwKq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Display
&lt;/h3&gt;

&lt;p&gt;We talked pretty extensively about this one already in our discussion about the Box Model, but I want to hit it at a different angle here.&lt;/p&gt;

&lt;p&gt;As we move forward in this series and as you progress in your career, you're going to learn that this &lt;code&gt;display&lt;/code&gt; property might be the most powerful CSS property of them all.  For example, what happens when we do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By specifying the &lt;code&gt;flex&lt;/code&gt; value of this &lt;code&gt;display&lt;/code&gt; property, we have opened up an entirely new world.  All the elements within this one are now going to be arranged and positioned based on the Flexbox specification, which is an entire tutorial on its own.  Likewise, we could do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By specifying this value, we once again have opened up an entirely new world of "CSS Grid".&lt;/p&gt;

&lt;p&gt;Both Flexbox and CSS Grid are extremely powerful components of CSS (and they are both relatively new).  They are so powerful that with them, we no longer need a CSS framework to make our development effective.&lt;/p&gt;

&lt;p&gt;We will come back to these in future lessons.&lt;/p&gt;

&lt;h2&gt;
  
  
  Must Know CSS Properties
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://youtu.be/dqaNvIJ4Fyk"&gt;Here is the video version of this section&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Through our discussion on the Box Model and Layout, I believe we have touched on some of the more important CSS properties, but there are hundreds more.  In this section, I want to share some of the most common by category.&lt;/p&gt;

&lt;p&gt;Don't worry if you can't remember all these; we will be using them heavily in our code challenges.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS Units of measure (pixels, rem, percentages, etc.)&lt;/li&gt;
&lt;li&gt;Color codes and CSS properties&lt;/li&gt;
&lt;li&gt;Font Properties&lt;/li&gt;
&lt;li&gt;Background Properties&lt;/li&gt;
&lt;li&gt;Writing "shorthand" CSS&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  CSS Units of Measure
&lt;/h3&gt;

&lt;p&gt;CSS doesn't require complex math, but it does require math.&lt;/p&gt;

&lt;p&gt;While there are many units of measure, we're going to focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pixels (and viewport units)&lt;/li&gt;
&lt;li&gt;Percentages&lt;/li&gt;
&lt;li&gt;rem and em units&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Pixels
&lt;/h4&gt;

&lt;p&gt;Let's start with pixels, which are by far the easiest to grasp.  Your computer screen is made of pixels, and a webpage is displayed on your computer screen, thus your HTML elements are always defined in terms of pixels.  &lt;/p&gt;

&lt;p&gt;We can use pixels to define font sizes, padding and margin amounts (remember, Box Model!), element heights and widths, and more.  For example, here are a few common properties we are about to talk about in action (using pixels).&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/BaQdLmm"&gt;Using pixels&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/BaQdLmm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;When using Firefox (or any browser) developer tools, the numbers that you see when you hover over HTML elements are expressed in pixels regardless of how you originally defined them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6t5retodpwa4u7ltnr3.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6t5retodpwa4u7ltnr3.JPG" alt="pixel units dev tools" width="800" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While we are talking about pixels, I want to revisit something we talked about in the prior lesson on the DOM.  Remember when we talked about these built-in properties?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The webpage height in pixels&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The webpage width in pixels&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As of right now, we only know how to find these numbers using JavaScript, but they are also available to us with CSS!  To use these in CSS, we can write the following lines of CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using &lt;code&gt;vw&lt;/code&gt; ("viewport width") and &lt;code&gt;vh&lt;/code&gt; ("viewport height"), we can assign elements to have dimensions equal to the entire width or height of the visible webpage.  By putting &lt;code&gt;100&lt;/code&gt; in front, we are saying, "Make this element 100% of the current viewport height/width".&lt;/p&gt;

&lt;p&gt;You won't have to use this often, but it will come in handy.&lt;/p&gt;

&lt;h4&gt;
  
  
  Percentages
&lt;/h4&gt;

&lt;p&gt;Take a look at this brainteaser.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/ExNvgMj"&gt;Using CSS percentages&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/ExNvgMj?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Read through the HTML and CSS and then ask yourself–if we have assigned a width of 100% to the &lt;code&gt;.progress-bar&lt;/code&gt; div, then why is it not equal to the width of the main container?&lt;/p&gt;

&lt;p&gt;The reason is because &lt;strong&gt;when defining dimensions using percentages, these percentages are relative to the parent element&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this case, &lt;code&gt;.inner-container&lt;/code&gt; has a width of &lt;code&gt;150px&lt;/code&gt;, while &lt;code&gt;.container&lt;/code&gt; has a width of &lt;code&gt;200px&lt;/code&gt;.  Since &lt;code&gt;.progress-bar&lt;/code&gt; is the child of &lt;code&gt;.inner-container&lt;/code&gt;, it will have a width equal to 100% * 150px, NOT 100% * 200px;&lt;/p&gt;

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

&lt;p&gt;If the parent container does not have a width defined, then the percentage will be relative to the &lt;strong&gt;first parent that does have a dimension defined&lt;/strong&gt;.  If we remove the width property from &lt;code&gt;.inner-container&lt;/code&gt;, then our progress bar will be equal in width to the main container.&lt;/p&gt;

&lt;p&gt;This seems complicated, but percentages are used heavily when we want to make our web applications responsive on all devices.  We won't talk much about responsive web design here in this tutorial, but consider what would happen if you defined an HTML element to have a width of &lt;code&gt;900px&lt;/code&gt;.  Mobile devices are usually between 400-500 pixels, which means the element that you have defined will overflow out of the visible screen (the "viewport") when your user sees it on a mobile device.  If we instead defined the width of this element as something like &lt;code&gt;90%&lt;/code&gt;, we no longer have this problem.  We will talk more about this concept later, but let's keep moving for now.&lt;/p&gt;

&lt;h3&gt;
  
  
  rem and em Units
&lt;/h3&gt;

&lt;p&gt;These measurements are &lt;strong&gt;specific to font sizes&lt;/strong&gt;.  We will soon cover font properties, but first let's understand how we measure the size of them.  Here are three ways that we can define the size of a font.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 16px is a "standard" value for normal text on most webpages */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 100% of the parent element's font size */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 100% of the root element's font size */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first case is simple, and oftentimes, you'll see it used on the root element, &lt;code&gt;html&lt;/code&gt;.  The subsequent two methods define the font size based on either the parent element or the root element.  Let's say we had the following HTML and CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph #1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"smaller-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Paragraph #2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Since the root font size is 16px, 1rem equals 16px */&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Since this element's parent, `body` has a font size 
of 16px, this will have a font-size of 0.8 * 16 = 12.8px */&lt;/span&gt;
&lt;span class="nc"&gt;.smaller-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.8em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example, although contrived, is a common way of defining font sizes.  We define the root element a hardcoded pixel value (usually 16 pixels), and then define elements within the html font sizes relative to that root font size.&lt;/p&gt;

&lt;h3&gt;
  
  
  Color Codes and CSS Properties
&lt;/h3&gt;

&lt;p&gt;I'm not going to get too detailed here; just give the basic overview.&lt;/p&gt;

&lt;p&gt;Here are the most common color-related CSS properties.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;color&lt;/code&gt; - defines the text color of the container or element&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;background-color&lt;/code&gt; - defines the background color of the element&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;border-color&lt;/code&gt; - defines the border color&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here are four valid ways to define a color.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;green&lt;/code&gt; - a built in value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rgb(0, 255, 0)&lt;/code&gt; - RGB stands for "red", "green", "blue".  Valid values are from 0-255, &lt;a href="https://stackoverflow.com/a/4986517/7437737"&gt;which is equal to one byte&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;#00ff00&lt;/code&gt; - The "hex" or &lt;a href="https://stackoverflow.com/a/22239907/7437737"&gt;"hexadecimal" version of the color&lt;/a&gt;.  The first two characters represent red, the second two green, and the third blue.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rgba(0, 255, 0, 0.8)&lt;/code&gt; - Same thing as RGB, but the last number represents the transparency value.  In this case, we are defining 80% transparency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While the built in colors like "green" or "blue" are just part of CSS, we can easily convert back and forth between RGB and Hex.  It is simply a matter of converting binary to hexadecimal and vice-versa.  There are &lt;a href="https://www.google.com/search?q=color+picker"&gt;plenty of online converters&lt;/a&gt; you can use to do this.&lt;/p&gt;

&lt;p&gt;And one more thing while we're here–check out &lt;a href="https://color.adobe.com/create"&gt;Adobe Color&lt;/a&gt; as a tool for building color themes and working with these color codes.&lt;/p&gt;

&lt;p&gt;As a quick review, if we wanted to make all paragraph elements a sky blue color, we could do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#16A6F5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;166&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;245&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Here is a list of color keywords - https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#color_keywords */&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;lightblue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Font Properties
&lt;/h3&gt;

&lt;p&gt;While we have already covered the &lt;code&gt;font-size&lt;/code&gt; property, there are a couple other important font properties to be aware of.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;font-family&lt;/code&gt; - defines the font that your webpage will use&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;font-size&lt;/code&gt; - defines the size of the font&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;font-weight&lt;/code&gt; - defines the thickness of the font (i.e. regular, bold, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;line-height&lt;/code&gt; - defines the spacing between lines of text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In most cases, you'll see the &lt;code&gt;font-family&lt;/code&gt; and &lt;code&gt;font-size&lt;/code&gt; defined at the root element, &lt;code&gt;html&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"Georgia"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first part of the &lt;code&gt;font-family&lt;/code&gt; property represents the actual family (i.e. "Georgia") while the second part represents the generic family (i.e. "serif"), which acts as a fallback value in case the main family is not able to load correctly in the webpage (usually due to unsupported fonts on certain browsers).&lt;/p&gt;

&lt;p&gt;For a list of font families and fallbacks, &lt;a href="https://www.w3.org/Style/Examples/007/fonts.en.html"&gt;this W3 page is a good reference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But what if you're not happy with the built-in browser fonts?  Adding a custom font can be done in a few different ways, but the most straightforward and common way is by adding a &lt;code&gt;link&lt;/code&gt; tag in the &lt;code&gt;head&lt;/code&gt; of your HTML document; just like you would a stylesheet.&lt;/p&gt;

&lt;p&gt;Let's say we wanted to add the Roboto font family to our webpage.  &lt;a href="https://fonts.google.com/specimen/Roboto?preview.text_type=custom&amp;amp;sidebar.open=true&amp;amp;selection.family=Roboto:wght@400;900"&gt;Head over to Google Fonts&lt;/a&gt; and copy that &lt;code&gt;link&lt;/code&gt; tags you see on the right side of the page.  It should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.gstatic.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&amp;amp;display=swap"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we wire these up to our HTML document, I want to point out one important thing.  You can see in the &lt;code&gt;href&lt;/code&gt; attribute, we have font weights of 400 and 900 selected.  In other words, we can use the &lt;code&gt;font-weight&lt;/code&gt; property with values of &lt;code&gt;400&lt;/code&gt; and &lt;code&gt;900&lt;/code&gt; to change the thickness of our text.  Let's go ahead and wire it up now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My Webpage&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.gstatic.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&amp;amp;display=swap"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"./path-to-stylesheet.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph #1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bold-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Paragraph #2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, all we have to do in our stylesheet is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Roboto'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if we wanted to make one of those paragraphs bold, we could do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.bold-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;900&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a Codepen showing this in action.  Please note that the process of adding a custom font family in Codepen is slightly different because the HTML code editor represents the &lt;code&gt;body&lt;/code&gt; and not the &lt;code&gt;html&lt;/code&gt; document.  Just go to Settings-&amp;gt;HTML and paste the &lt;code&gt;link&lt;/code&gt; tags into the "Stuff for head" section.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/RwoZKew"&gt;Including Custom Fonts&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/RwoZKew?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Background Properties
&lt;/h3&gt;

&lt;p&gt;Whether we are talking about background colors, background images, or how these backgrounds are positioned, the following CSS properties are really helpful to keep in the back pocket.&lt;/p&gt;

&lt;p&gt;Each of these properties will affect the content area of the Box Model (including padding, but excluding border and margin).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;background-color&lt;/code&gt; - changes the color of an HTML element&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;background-image&lt;/code&gt; - uses an image as a background&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;background-position&lt;/code&gt; - if using a background image, positions the image&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;background-repeat&lt;/code&gt; - determines whether a background image is repeated&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;background-size&lt;/code&gt; - changes the size of the background image&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Changing the background color is pretty straightforward, but make sure that the element you are styling has a width and a height either explicitly or implicitly.  After all, an element that has no dimensions cannot have a background!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#46D5F2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding a background image is a bit trickier.  If you are adding a background image, you most likely will be working with a picture, and therefore, you want that picture to fill the entire visible screen (the "viewport").  I have no intention in this massive post to walk you through all the possible combinations, so let's look at an extremely common example that you will see and use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Some Centered Large Text&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we need to get a high-resolution image (at least 1920x1080, but larger is preferable) for our background.  Low-res images will NOT look good on large screens!  &lt;a href="https://www.thediygolfer.com/wp-content/uploads/2020/12/homepage-background.jpg"&gt;Here is one from my golf site.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All we need is the image link and we should be set!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* This is a basic CSS reset.  By default, the body will have
   margin and padding that will prevent our background image from
   taking up the entire screen */&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Sets the background image */&lt;/span&gt;
&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://www.thediygolfer.com/wp-content/uploads/2020/12/homepage-background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;right&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-repeat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;no-repeat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Centers the text container on the page */&lt;/span&gt;
&lt;span class="nc"&gt;.text-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a lot going on here, I know.  What I want you to focus on are the following things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I have set the &lt;code&gt;.container&lt;/code&gt; to have a &lt;code&gt;100vh&lt;/code&gt; and &lt;code&gt;100vw&lt;/code&gt;.  This ensures that the HTML element with the background occupies the entire visible webpage, or the "viewport"&lt;/li&gt;
&lt;li&gt;I have set the margin and padding to 0 for the &lt;code&gt;body&lt;/code&gt; element to remove browser default styles that will prevent our background from occupying the entire page.  Go ahead and remove this block of code in the Codepen and see what happens.&lt;/li&gt;
&lt;li&gt;Each of the background properties have a set of possible values.  These are good defaults.  The only property that might be worth changing is the &lt;code&gt;background-position&lt;/code&gt; property depending on what parts of your image you want to be shown.&lt;/li&gt;
&lt;li&gt;Everything else that I didn't comment on will become part of your "CSS vocabulary" with practice (and I will likely cover them in the code challenge for this lesson).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the end result.  I highly suggest clicking through this and removing CSS properties one at a time to see what they do to the overall webpage.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/WNoEpKK"&gt;Background images&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/WNoEpKK?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing Shorthand CSS
&lt;/h3&gt;

&lt;p&gt;And finally, the last thing I want to cover here is something that might be confusing to you like it was me when I was starting out.  Many of the CSS properties that we have covered have "shorthand" ways of writing them.  When talking about the Box Model, we can define a border around an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;dashed&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a 1 pixel, dashed black line as a border.  But...&lt;/p&gt;

&lt;p&gt;We could have written this across three separate properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dashed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In other words, the first way was the "shorthand" way of writing this CSS rule.  We can also do this with other properties like &lt;code&gt;margin&lt;/code&gt;.  Here's the long way to define margin for an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a shorter way to write the same CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you want the same margin value on all sides, this is all you have to do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.some-element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you write CSS, you will pick up on these "shorthand" ways of writing it.  I know it is confusing now and tough to remember what to use and when, but if you are ever lost, remember, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference#index"&gt;you've got the documentation available to you&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  A Systematic Way to Write CSS Effectively
&lt;/h2&gt;

&lt;p&gt;In my experience, the real key to using CSS effectively is to ask the following four questions in order, &lt;strong&gt;every time you style a webpage&lt;/strong&gt;.  These will become second nature eventually.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do I want to arrange these HTML elements on the page?&lt;/li&gt;
&lt;li&gt;How does this arrangement look in the form of HTML?&lt;/li&gt;
&lt;li&gt;How can I use CSS to achieve the layout I have imagined?&lt;/li&gt;
&lt;li&gt;How should each element be styled?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Talking about CSS in isolation isn't helpful.  We have to consider the HTML part too.&lt;/p&gt;

&lt;p&gt;I'm going to walk you through these four questions using an example similar to the one below.  Take a look at the webpage we looked at earlier:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/dyORWWm"&gt;CSS Layout and Style Example&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/dyORWWm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: How do I want to arrange the elements?
&lt;/h3&gt;

&lt;p&gt;In the example above, my goal is to have two boxes, horizontally arranged side-by-side with text in them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: How does this arrangement look in HTML?
&lt;/h3&gt;

&lt;p&gt;Since I have two boxes, I probably need two &lt;code&gt;div&lt;/code&gt; elements.  These &lt;code&gt;div&lt;/code&gt; elements are perfect "containers" for things like this.  I also need a "main" container, so I'll wrap everything in another &lt;code&gt;div&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Furthermore, I need a heading and some paragraph text in each box.  The most basic representation of this layout in HTML would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, I need to put some text in the &lt;code&gt;h2&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt; elements and add a few classes to the elements (so that I can select them easily with CSS), but this represents the "skeleton" that I'm trying to imagine in this step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: How can I use CSS to achieve the layout I have imagined?
&lt;/h3&gt;

&lt;p&gt;In this step, we're focusing on getting those HTML elements arranged in the correct spots on the webpage.  We are NOT worried about how pretty they look yet.&lt;/p&gt;

&lt;p&gt;Unfortunately, this step is where experience using CSS comes in handy.  There are several "layout" CSS properties to use here, and we can actually achieve the same result in a couple different ways.  Since I will be walking through these properties later, I'm going to just give them to you now.&lt;/p&gt;

&lt;p&gt;But the first thing we need to do is modify our HTML so that we have the necessary selectors ready to use!  Here's how I would modify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Box 1&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Box 2&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sure, I could have used ID attributes instead of classes, but in this example, it doesn't matter.  We just need something that will make writing our CSS easier.  Here is how our HTML looks without CSS layout properties (I added borders so you can visualize it better).&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/GRNvRPo"&gt;Layout only example (html only)&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/GRNvRPo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;By default, these will be stacked on top of each other vertically (we'll talk about why later).  Since we want them to be arranged horizontally, we need to add some CSS.  Here's one way to do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;float&lt;/code&gt; property will break the first box out of its "natural" layout and the &lt;code&gt;width&lt;/code&gt; will make it take up 50% of the page.  This is the easiest way to achieve our desired result, but as you start writing more and more CSS, you'll realize that using the &lt;code&gt;float&lt;/code&gt; property for layouts is very cumbersome and produces some unexpected results.  In the next lesson, we will learn about Flexbox, which is how I would prefer to achieve this layout.  Don't worry about how this works yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is our result after adding this CSS.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/ZEBJEdj"&gt;Layout only example&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/ZEBJEdj?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;At this point, we have successfully arranged the items in the right place on the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: How should each element be styled?
&lt;/h3&gt;

&lt;p&gt;The last step is in my opinion, the easiest.  All we have to do now is take our elements that we have arranged on the page and give them nice colors, borders, spacing, etc.  Let's add the following CSS to our existing webpage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box-1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box-2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Starting from the top, we have added a &lt;code&gt;text-align&lt;/code&gt; property which will center all the text elements inside our &lt;code&gt;div&lt;/code&gt; containers.  We also added &lt;code&gt;margin&lt;/code&gt; and &lt;code&gt;padding&lt;/code&gt; (will talk about this in a minute), which just spaces things out nicely.  We then add a green &lt;code&gt;border&lt;/code&gt; and &lt;code&gt;color&lt;/code&gt; (font color) to the &lt;code&gt;box-1&lt;/code&gt; class and the same properties in blue for &lt;code&gt;box-2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's our final result.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/MWbvYgX"&gt;Layout + Style Example&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/MWbvYgX?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  A Project to Learn CSS
&lt;/h2&gt;

&lt;p&gt;Like most things in web development, the only true way to digest this stuff is to build something.  Instead of giving you a boring overview of all the possible CSS properties, we're going to use what we've learned in this lesson and start building something real.&lt;/p&gt;

&lt;p&gt;The challenge that we are doing is from a site called Frontend Mentor, which provides really nice UI designs (that I could not design myself) and presents them as HTML/CSS/JS challenges.&lt;/p&gt;

&lt;p&gt;Here is the challenge that we will be completing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt75eqwhamskgms8mxpi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt75eqwhamskgms8mxpi.jpg" alt="desktop card preview" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we know how to write JavaScript, HTML, and now CSS, we should be able to complete this entire challenge!  I will be releasing some supplemental CSS videos on responsive web design, Flexbox, and CSS grid, so I suggest supplementing this challenge with those videos and trying parts of it on your own.  I would not expect you to be able to build this on your own, but there will be many opportunities throughout to pause the video and try it for yourself.&lt;/p&gt;

&lt;p&gt;Best of luck, &lt;a href="https://youtu.be/zwBoEwUD__0"&gt;here is the video solution!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>HTML Crash Course + Overview of the DOM #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Tue, 09 Feb 2021 22:48:51 +0000</pubDate>
      <link>https://dev.to/zachgoll/html-crash-course-overview-of-the-dom-fullstackroadmap-eb5</link>
      <guid>https://dev.to/zachgoll/html-crash-course-overview-of-the-dom-fullstackroadmap-eb5</guid>
      <description>&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;By the end of this lesson, I want you to clearly understand the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is HTML?&lt;/li&gt;
&lt;li&gt;What is the Document Object Model? (DOM)&lt;/li&gt;
&lt;li&gt;What is the relationship between JavaScript, HTML, and CSS?&lt;/li&gt;
&lt;li&gt;How to write a basic webpage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the end of the lesson, we will be building this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/qwUeoBBmQUW1hLxXRn/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/qwUeoBBmQUW1hLxXRn/giphy.gif" alt="random joke" width="480" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=tWZcRgaFdaE"&gt;See this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;p&gt;This is part of my full-stack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first full-stack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back. This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Building a House
&lt;/h2&gt;

&lt;p&gt;If we were building a house, we would have to follow three main steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build the structure (i.e. wood, concrete, brick, roofing, etc.)&lt;/li&gt;
&lt;li&gt;Set up plumbing, electric, water lines, and other functional requirements&lt;/li&gt;
&lt;li&gt;Make the house look good with paint, siding, and landscaping&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If our house was a website, #1 is the HTML, #2 is the JavaScript, and #3 is the CSS.&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;could&lt;/strong&gt; live in your house with only the structure (HTML), but it wouldn't be pleasant.&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;could&lt;/strong&gt; live in your house with only the structure (HTML) and decorative touches (CSS), but unfortunately, you'd be living in a beautiful house where the toilets don't flush and the light switches don't turn on the lights.&lt;/p&gt;

&lt;p&gt;HTML, CSS, and JavaScript work &lt;strong&gt;together&lt;/strong&gt;. While the only true requirement for a webpage is HTML, a modern web developer must deeply understand the connection between the three and learn to use each effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  We're skipping CSS... For now
&lt;/h2&gt;

&lt;p&gt;While you might see a few lines of CSS within this lesson (where necessary for an explanation of an HTML concept), the goal is not to learn CSS in this lesson.&lt;/p&gt;

&lt;p&gt;We have plenty to learn with HTML alone! Don't worry though, the next lesson will be a CSS crash course :)&lt;/p&gt;

&lt;p&gt;Remember, CSS is the styling of the web, and is not necessary to build a functional webpage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Essential Concepts of HTML (HyperText Markup Language)
&lt;/h2&gt;

&lt;p&gt;Like we did with the JavaScript section of this course, I'm not going to show you EVERY DETAIL of HTML. While we have far less ground to cover here than we did with JavaScript (HTML is much simpler), there are still HTML concepts that are overkill for you to learn if you are trying to become a web developer quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example&lt;/strong&gt;, HTML has a "tag" (we'll talk more on this) called &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; which allows you to create tables. I &lt;strong&gt;could&lt;/strong&gt; spend an entire lesson teaching you how to create and style tables in HTML, but &lt;strong&gt;I won't&lt;/strong&gt; because even to this day, I use a &lt;a href="https://divtable.com/generator/"&gt;table generator like this&lt;/a&gt; to create my HTML tables and styles. Here's a table that I created in a few minutes using the table generator tool.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/eYdXbxO"&gt;Basic Table&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/eYdXbxO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This code above is hosted on Codepen, which we will be using frequently for the next few lessons. I recommend &lt;a href="https://codepen.io/accounts/signup"&gt;creating a free account&lt;/a&gt; so you can follow along.&lt;/p&gt;

&lt;p&gt;Instead of spending all our time on something like HTML tables, we will be spending a lot of time on things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Commonly used HTML tags (&lt;code&gt;html&lt;/code&gt;, &lt;code&gt;body&lt;/code&gt;, &lt;code&gt;head&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, &lt;code&gt;input&lt;/code&gt;, &lt;code&gt;span&lt;/code&gt;, &lt;code&gt;h1&lt;/code&gt;, &lt;code&gt;h2&lt;/code&gt;, &lt;code&gt;img&lt;/code&gt;, &lt;code&gt;button&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;HTML attributes (&lt;code&gt;style&lt;/code&gt;, &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Structure of an HTML document
&lt;/h3&gt;

&lt;p&gt;This is what we call "HTML boilerplate", which just means that no matter what type of webpage you are creating, it will ALWAYS follow this structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Site Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- This is an HTML comment 

    It looks different than our JavaScript comments
    and can be used across multiple lines

    --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this is all that is necessary for a webpage, here is a more "real world" version of HTML boilerplate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Example Site&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"An example HTML site"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"author"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Zach Gollwitzer"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"css/styles.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"js/scripts.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't have to memorize this, but keep it handy.&lt;/p&gt;

&lt;p&gt;(Optional section) For those curious, here is what some of that cryptic stuff means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;!doctype html&lt;/code&gt; - Tells the web browser to expect an HTML document. This is not an HTML element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lang="en"&lt;/code&gt; - Tells search engines and web browsers what language this webpage is written in. &lt;a href="https://www.w3schools.com/tags/ref_country_codes.asp"&gt;Here are all the valid country codes.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;charset="utf-8"&lt;/code&gt; - This defines what character set to use and is a &lt;a href="https://www.w3schools.com/html/html_charset.asp"&gt;very involved topic&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;html&amp;gt;&amp;lt;/html&amp;gt;&lt;/code&gt; - The HTML container&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&lt;/code&gt; - Stores all the metadata about the webpage&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;&lt;/code&gt; - Look up at the text in your browser's tabs. The contents of this will represent the tab name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; - Nope, not &lt;code&gt;&amp;lt;meta&amp;gt;&amp;lt;/meta&amp;gt;&lt;/code&gt;. Some HTML tags are "self closing". This just defines useful information for the browser and search engines to use when viewing the webpage.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; - This allows you to connect your CSS stylesheet. We will be talking more about this in a future lesson.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; - This allows you to connect JavaScript code to your HTML document. We will cover this later in the post when we talk about the document object model (DOM).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  HTML Tags and Attributes
&lt;/h3&gt;

&lt;p&gt;Here is the basic structure of an HTML element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdlfbnxq9inahuhwa6nle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdlfbnxq9inahuhwa6nle.png" alt="html element" width="400" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's walk through each piece here. Here is the most basic way to write HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; is the "opening" tag that tells the webpage that we are starting an HTML element. &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt; is the "closing" tag (notice the &lt;code&gt;/&lt;/code&gt;) that says to the browser, "hey, I'm done with the contents of this HTML element.&lt;/p&gt;

&lt;p&gt;There are many HTML tags available to you (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element"&gt;you can see them all here&lt;/a&gt;), but as a web developer starting out, you will only need a handful of them to create beautiful webpages and apps.&lt;/p&gt;

&lt;p&gt;Let's add some content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Here is some content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can write whatever you want within the bounds of the two HTML tags, &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt;. Now, let's add an attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-first-class"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Here is some content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The word &lt;code&gt;class&lt;/code&gt; is the attribute, and &lt;code&gt;"my-first-class"&lt;/code&gt; is the &lt;strong&gt;value&lt;/strong&gt; we are giving this attribute. Think about it like the JavaScript variables we covered in the prior lessons of this series.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="err"&gt;= "&lt;/span&gt;&lt;span class="nc"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code is JavaScript, NOT HTML, but it is a very &lt;em&gt;similar concept&lt;/em&gt; to the attribute shown above.&lt;/p&gt;

&lt;p&gt;Just like you can use a variety of HTML tags, you can also use a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes"&gt;variety of HTML attributes&lt;/a&gt; that will affect the behavior of that element.&lt;/p&gt;

&lt;p&gt;We will talk about these tags shortly, but first, we need to make a few distinctions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tags vs. Elements
&lt;/h3&gt;

&lt;p&gt;Before we get any further, let's distinguish between a "tag" and an "element". The terms are often used interchangeably, but I generally view an "element" as a complete unit while I think of a "tag" as a symbol.&lt;/p&gt;

&lt;p&gt;Here's an element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"paragraph-style"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's a tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will use "tag" to speak about &lt;em&gt;function&lt;/em&gt; and "element" to speak about &lt;em&gt;general structure&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of HTML tags
&lt;/h3&gt;

&lt;p&gt;In my head, there are two levels of classification when it comes to HTML tags. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element"&gt;This page&lt;/a&gt; classifies HTML tags into many more categories, but I think my simplified view will help you as a beginner.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Normal vs. "self-closing" tags&lt;/li&gt;
&lt;li&gt;Container vs. Standalone tags&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Normal vs. Self-Closing Tags
&lt;/h4&gt;

&lt;p&gt;Most HTML tags have an "opening" and "closing" component to them. Here are some examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;strong&amp;gt;&amp;lt;/strong&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But some elements are what we call "self-closing". Here are common examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can nest elements within a normal HTML element while you cannot nest elements within a self-closing HTML element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Correct usage --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;some content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- INCORRECT usage (will not render) --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="na"&gt;p&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;some content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Container vs. Standalone tags
&lt;/h4&gt;

&lt;p&gt;We know that we cannot "nest" or "embed" elements within a self-closing HTML element, but when should we be nesting HTML elements within the "normal" elements?&lt;/p&gt;

&lt;p&gt;For example, the following HTML &lt;strong&gt;is valid&lt;/strong&gt;, but should we write it this way?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  Some content
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;some nested content&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;more nested content&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NO!!&lt;/strong&gt; While this HTML will render in the browser, it is improperly using the HTML tags. Some HTML tags such as &lt;code&gt;div&lt;/code&gt;, &lt;code&gt;table&lt;/code&gt;, &lt;code&gt;ol&lt;/code&gt;, &lt;code&gt;ul&lt;/code&gt;, and &lt;code&gt;body&lt;/code&gt; are meant to have nested elements within them. Other HTML tags such as &lt;code&gt;h1&lt;/code&gt;, &lt;code&gt;h2&lt;/code&gt;, &lt;code&gt;h3&lt;/code&gt;, &lt;code&gt;h4&lt;/code&gt;, &lt;code&gt;h5&lt;/code&gt;, &lt;code&gt;h6&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, and &lt;code&gt;strong&lt;/code&gt; are &lt;em&gt;not&lt;/em&gt; good as "containers" for other elements.&lt;/p&gt;

&lt;p&gt;To learn more, let's look at a list of common HTML tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common HTML Tags
&lt;/h2&gt;

&lt;p&gt;To avoid being a complete redundancy of all the great resources that document HTML tags, this section will provide you with the &lt;strong&gt;most common&lt;/strong&gt; HTML tags that I use as a full-stack developer.&lt;/p&gt;

&lt;p&gt;Remember, this is not an exhaustive list, but rather the &lt;strong&gt;essential&lt;/strong&gt; tags you'll need to know. You can visit &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element"&gt;this reference page&lt;/a&gt; for all available tags.&lt;/p&gt;

&lt;p&gt;The Codepen below has two sections. On the left is the HTML code. On the right is the output.&lt;/p&gt;

&lt;p&gt;Study these common tags for a few minutes, but don't obsess over memorizing them. We will do a challenge exercise later in this lesson that will help you apply the concepts. Additionally, &lt;strong&gt;you can always &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element"&gt;look them up in the documentation&lt;/a&gt;&lt;/strong&gt;. I suggest opening this in Codepen for a full-screen view.&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/poEYBXm"&gt;Common HTML Tags&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/poEYBXm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML is NOT case-sensitive!
&lt;/h3&gt;

&lt;p&gt;As you were looking through the HTML, you might have noticed that all of the tags were written in lowercase letters. This is generally how you should write HTML, but the following code is valid too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;HTML is not case-sensitive&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Line breaks do not affect HTML
&lt;/h3&gt;

&lt;p&gt;You also might have noticed when looking through the code that there was a significant space between blocks of HTML code, but in the output, those same spaces did not exist.&lt;/p&gt;

&lt;p&gt;You might think that the following code would result in a large space between the paragraphs:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/oNzVrvM"&gt;Line Breaks Don't Matter in HTML&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/oNzVrvM?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Global Attributes vs. Element Attributes
&lt;/h3&gt;

&lt;p&gt;Again, here is an HTML element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdlfbnxq9inahuhwa6nle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdlfbnxq9inahuhwa6nle.png" alt="HTML element" width="400" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The attribute &lt;code&gt;class&lt;/code&gt; is a global attribute, but what exactly does this mean?&lt;/p&gt;

&lt;p&gt;It would be useless for me to walk you through ALL of the possible attributes for ALL HTML tags. Instead, you need to understand &lt;em&gt;how&lt;/em&gt; they work.&lt;/p&gt;

&lt;p&gt;Remember in the &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/6-intermediate-javascript/"&gt;prior lesson&lt;/a&gt; where we talked about the various JavaScript objects and their built-in methods?&lt;/p&gt;

&lt;p&gt;And remember when we tried to call an Array method on a String data type?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;i am a string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// This won't work because reverse() is a built-in method&lt;/span&gt;
&lt;span class="c1"&gt;// on Arrays, NOT Strings!&lt;/span&gt;
&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// TypeError: str.reverse is not a function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTML attributes are very similar to these object methods. Each HTML tag (&lt;code&gt;p&lt;/code&gt;, &lt;code&gt;div&lt;/code&gt;, &lt;code&gt;img&lt;/code&gt;, etc.) has a set of element attributes that can be used on them to modify their behavior and styling. There are also a set of global attributes that can be used on ALL HTML tags.&lt;/p&gt;

&lt;p&gt;For example, you CAN put a &lt;code&gt;src&lt;/code&gt; attribute on an &lt;code&gt;img&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.somewebsite.com/images/image1.png"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you CANNOT put &lt;code&gt;src&lt;/code&gt; on a &lt;code&gt;p&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- INCORRECT --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.somewebsite.com/images/image1.png"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It won't throw an error, but it won't do anything useful. This is because &lt;code&gt;src&lt;/code&gt; is NOT a global attribute. It is an element-specific attribute that pertains to &lt;code&gt;img&lt;/code&gt; tags.&lt;/p&gt;

&lt;p&gt;On the other hand, you COULD do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"some-style"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.somewebsite.com/images/image1.png"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"some-style"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, we are using the &lt;code&gt;class&lt;/code&gt; attribute on both elements because it is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class"&gt;global attribute&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mid-Lesson Code Challenge
&lt;/h2&gt;

&lt;p&gt;To check your knowledge, we are going to stop here and apply the concepts we just learned.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://codepen.io/accounts/signup"&gt;Create a Codepen account for free&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://codepen.io/zg_dev/pen/vYXMbLJ"&gt;Open this Pen&lt;/a&gt; and click "Fork" in the bottom right corner of your screen. This will allow you to edit it on your own account.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6d2gek3ax5jak1mh5zwy.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6d2gek3ax5jak1mh5zwy.JPG" alt="codepen fork" width="601" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Solve the challenge below, and tag me with your solution on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt;! Be sure to use the #100DaysOfCode hashtag in your Tweet!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A few hints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The big text is an &lt;code&gt;h1&lt;/code&gt; element.&lt;/li&gt;
&lt;li&gt;Don't worry about the colors, borders, and text styles. They will happen automatically if you build it correctly with the HTML&lt;/li&gt;
&lt;li&gt;Be sure to personalize the content (including links) so you can share it! You can share it on Twitter by clicking that share link at the bottom right corner of your Codepen page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://codepen.io/zg_dev/pen/yLarZeW"&gt;Here is the solution&lt;/a&gt;, but don't cheat yourself! Give it a try first!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn9eqksc42u4l592s6y0p.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn9eqksc42u4l592s6y0p.JPG" alt="codepen" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to follow along for the rest of this tutorial
&lt;/h2&gt;

&lt;p&gt;In the next part of this lesson, we will be connecting some JavaScript with a Codepen HTML document.  Here is how you can follow along.&lt;/p&gt;

&lt;p&gt;First, you'll notice that in each Codepen "Pen", there is a section for HTML, CSS, and JavaScript.  Any JavaScript you type into the JavaScript section will be automatically connected to your HTML document.  Normally, you would have to do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;

    &amp;lt;title&amp;gt;Example Site&amp;lt;/title&amp;gt;
    &amp;lt;meta name="description" content="An example HTML site" /&amp;gt;
    &amp;lt;meta name="author" content="Zach Gollwitzer" /&amp;gt;

    &amp;lt;link rel="stylesheet" href="css/styles.css" /&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;


    &amp;lt;!-- Normally, you have to manually connect your JavaScript code to your HTML code
          like we are doing here.  We will talk more about this later.
    --&amp;gt;
    &amp;lt;script src="js/scripts.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Codepen, all of this is &lt;strong&gt;automatically taken care of for you&lt;/strong&gt;.  All you have to do is start typing some JavaScript in the designated area.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faguwomo4m4rhsix03v10.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faguwomo4m4rhsix03v10.JPG" alt="codepen" width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But... What if you want to experiment around with some JavaScript before typing it here?  You have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use Codepen's built-in Console (bottom left corner)&lt;/li&gt;
&lt;li&gt;Use the browser console&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Unfortunately for us&lt;/strong&gt;, option #1 isn't great because Codepen's console isn't very interactive.  Option #2 isn't great because within the Firefox browser (which we have been using in this series), the dev tools console does not properly connect with Codepen.&lt;/p&gt;

&lt;p&gt;I hate to come up with a workaround solution for us, but here it is...  I suggest using Google Chrome with your Codepen Pens.  Don't worry, these problems won't exist once we start developing locally, but for now, it's what we have to deal with.  So open Google Chrome, and once there, you can use the dev tools to interact with your Codepen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/noFAhwYM5K4QV93J1z/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/noFAhwYM5K4QV93J1z/giphy.gif" alt="console codepen" width="480" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, make sure the "CodePen" is selected for the JavaScript execution context:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/5smHIEAVJSPYFcLqmi/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/5smHIEAVJSPYFcLqmi/giphy.gif" alt="js context" width="574" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Document Object Model (DOM)
&lt;/h2&gt;

&lt;p&gt;So you just learned HTML for the first time and now, I'm throwing you a curve-ball. &lt;strong&gt;The Document Object Model, or "DOM" is the bridge between JavaScript and HTML.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most web development courses teach HTML prior to teaching JavaScript, but I did the opposite because understanding the DOM without having a basic background in JavaScript is a fools errand. I learned HTML before JavaScript and when we got to the DOM section, I had NO IDEA what the instructor was talking about.&lt;/p&gt;

&lt;p&gt;And that is a shame, because a strong understanding of the DOM will go a long way in today's world where front-end frameworks like React, Vue, and Angular dominate the web. All of these frameworks heavily leverage the DOM and the React framework even defines its own "virtual DOM".&lt;/p&gt;

&lt;h3&gt;
  
  
  Why are we talking about the DOM?
&lt;/h3&gt;

&lt;p&gt;No matter what front-end framework you use, in some way or another, it will be leveraging the DOM.  You may not see how that is happening due to layers of abstraction, but at the basis of every front-end application, the DOM is what allows us to connect our JavaScript to our HTML and make things happen.&lt;/p&gt;

&lt;p&gt;While you don't need to be an expert in this topic, you should understand what the DOM is and how it plays into the code you are writing.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what is the DOM (Document Object Model)?
&lt;/h3&gt;

&lt;p&gt;The "DOM" is &lt;strong&gt;NOT&lt;/strong&gt; a programming language.  The "DOM" is also not part of JavaScript.  So what is it?&lt;/p&gt;

&lt;p&gt;The DOM is an API for an HTML document. What is an API? Here is the definition I came up with in &lt;a href="https://www.zachgollwitzer.com/posts/2020/what-is-an-api/"&gt;my post explaining APIs&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A software API can be thought of as a "user manual" that allows developers to do something useful with 3rd party software/hardware without knowing the inner-workings of that software/hardware.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, you want to do something programmatically with your webpage, but you don't want to become an expert in the low-level details of how HTML actually works (i.e. how it is actually rendered on a webpage, NOT how to write it).&lt;/p&gt;

&lt;p&gt;I know your head is probably spinning, so let's make this real. Take a look at the following HTML document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My webpage&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Welcome to my HTML tutorial&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Click the button below to begin&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Start Tutorial&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is what it looks like (I put some basic CSS styles on it, but again, don't worry about them YET).&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/LYRoVKO"&gt;Basic HTML Document&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/LYRoVKO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Go ahead, click that button.&lt;/p&gt;

&lt;p&gt;What does it do?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTHIN. IT'S USELESS.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we want that button to do something, we need to bring in our friend, JavaScript. As we talked about earlier, JavaScript is what brings a webpage alive.&lt;/p&gt;

&lt;p&gt;But how do we make that happen? Somehow, we need to &lt;strong&gt;identify&lt;/strong&gt; that button HTML element and tell it to do something when someone clicks it. So it's a two-step process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify an HTML element using JavaScript&lt;/li&gt;
&lt;li&gt;Once identified, instruct it to do something in JavaScript&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Identifying HTML Elements with JavaScript
&lt;/h3&gt;

&lt;p&gt;This is where the DOM comes in. As we said, the DOM is an API for accessing HTML elements.&lt;/p&gt;

&lt;p&gt;Here's how we identify that button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is JavaScript running in your web browser, and all we are doing is assigning our identified HTML element to a variable called &lt;code&gt;btn&lt;/code&gt;. But what is &lt;code&gt;document&lt;/code&gt;? And what is this &lt;code&gt;querySelector()&lt;/code&gt; method on it?&lt;/p&gt;

&lt;h3&gt;
  
  
  An Analogy for Understanding the DOM (Document Object Model)
&lt;/h3&gt;

&lt;p&gt;At this point, I'm assuming you kind of understand what I'm saying, but it's still fuzzy. That's okay.&lt;/p&gt;

&lt;p&gt;To aid our discussion, &lt;strong&gt;think of an HTML document as a paper map, and think of the DOM &lt;em&gt;combined with&lt;/em&gt; HTML as Google Maps&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff9039eoiz7dx6mq71v1v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff9039eoiz7dx6mq71v1v.jpg" alt="map" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Photo by &lt;a href="https://unsplash.com/@glenncarstenspeters?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Glenn Carstens-Peters&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/paper-map?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;There's not much you can do with a physical, paper map. But with Google Maps (or something similar), we have unlimited potential.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://123movies-to.org"&gt;123movies&lt;/a&gt;&lt;br&gt;.mapouter{position:relative;text-align:right;height:250px;width:450px;}&lt;a href="https://www.embedgooglemap.net"&gt;embedgooglemap.net&lt;/a&gt;.gmap_canvas {overflow:hidden;background:none!important;height:250px;width:450px;}&lt;/p&gt;

&lt;p&gt;With Google Maps, we can build applications like Uber because it has a pre-defined structure (API) for using it! We can "plug in" all sorts of integrations.&lt;/p&gt;

&lt;p&gt;An HTML document is a bit boring on its own; just like a paper map. But once we define a structural representation of that HTML document (the DOM), we have unlimited possibilities!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Structure of the DOM (HINT: it's a tree!)
&lt;/h2&gt;

&lt;p&gt;We call this a &lt;code&gt;String&lt;/code&gt; object in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;some string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We call this a &lt;code&gt;Number&lt;/code&gt; object in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We call this an &lt;code&gt;null&lt;/code&gt; primitive in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;someVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we call this an &lt;code&gt;HTMLElement&lt;/code&gt; object in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;HTMLElement&lt;/code&gt; data type is not native to JavaScript.  It's not even available in server-side (NodeJS) JavaScript!  So what is it?&lt;/p&gt;

&lt;p&gt;This is just one of many "leaves" that makes up the "DOM Tree".  More on this soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  A 10,000 Foot View of the DOM
&lt;/h2&gt;

&lt;p&gt;Before we get into this, let me give you four things to consider as we explore this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The DOM is complex, and at your current skill level (assuming you're following along with this series), you will NOT fully grasp it.  &lt;strong&gt;That's okay.  Try to follow the high-level themes, but don't stress over the details.&lt;/strong&gt;  This will not make or break your ability to program web apps.&lt;/li&gt;
&lt;li&gt;The DOM is not part of the JavaScript programming language (but can be used by it; hence why we call it an "API")&lt;/li&gt;
&lt;li&gt;Each browser has a slightly different implementation of the DOM, but these differences shouldn't matter to most web developers.&lt;/li&gt;
&lt;li&gt;The DOM is not a programming language, but rather a "model" or "representation" of an existing structure (HTML).  It adapts a lot of OOP (Object Oriented Programming) concepts which can be confusing since we haven't learned it yet, but just remember, &lt;strong&gt;each piece of the HTML can be "modeled" according to properties and methods (what it is made of and what it can do)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To understand this as a beginner, we're going to need some visuals and work our way slowly into the details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwrgfncz79pm1cb0vshsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwrgfncz79pm1cb0vshsb.png" alt="the dom" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, I want you to get clear on a couple of things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The browser itself is programmable&lt;/li&gt;
&lt;li&gt;Each browser tab contains exactly 1 HTML "Document" (this is technically not true if you have an &lt;code&gt;iframe&lt;/code&gt;, but not important here)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Window Object
&lt;/h3&gt;

&lt;p&gt;So what can that browser of yours do that you would want to program?  Here are a few ideas:&lt;/p&gt;

&lt;p&gt;We can...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scroll up and down through the content of a webpage&lt;/li&gt;
&lt;li&gt;Refresh the page&lt;/li&gt;
&lt;li&gt;Resize the browser window&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the best part?  We can write JavaScript to do this via the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To programmatically control the browser itself,&lt;/strong&gt; we will use a global DOM object called &lt;code&gt;window&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window"&gt;Here is the link&lt;/a&gt; to its official documentation that I recommend you quickly glance at.&lt;/p&gt;

&lt;p&gt;Per the photo above, you can think of the &lt;code&gt;window&lt;/code&gt; object as a representation of the Browser.  &lt;strong&gt;More specifically, it represents a single tab within your browser&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some common Window methods
&lt;/h4&gt;

&lt;p&gt;To get you started, go ahead and open up your browser dev tools and execute the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Opens an alert box&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I love programming&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Opens a new browser tab&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Scrolls (smoothly) down by exactly 1 page&lt;/span&gt;
&lt;span class="c1"&gt;// (make sure you are on a webpage that has enough content to scroll)&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scrollBy&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;smooth&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Reloads the browser tab&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since &lt;code&gt;window&lt;/code&gt; is a globally available object in the browser, you don't need to preface all of your commands with it.  The following code will work the same as the code above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Opens an alert box&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I love programming&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Opens a new browser tab&lt;/span&gt;
&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.google.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Scrolls (smoothly) down by exactly 1 page&lt;/span&gt;
&lt;span class="c1"&gt;// (make sure you are on a webpage that has enough content to scroll)&lt;/span&gt;
&lt;span class="nf"&gt;scrollBy&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;innerHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;smooth&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Some Common Window Properties
&lt;/h4&gt;

&lt;p&gt;While these are some of the common "methods" that you might be using, here are some of the common "properties" that belong to the global &lt;code&gt;window&lt;/code&gt; object.  Feel free to type these into your dev tools Console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Width and height in pixels of the space that displays the HTML&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; 
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&lt;/span&gt;

&lt;span class="c1"&gt;// Width and height in pixels of the entire browser window&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;outerHeight&lt;/span&gt; 
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;outerWidth&lt;/span&gt;

&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt; &lt;span class="c1"&gt;// You'll use this later in the series for storing temporary information in the browser&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt; &lt;span class="c1"&gt;// The URL you are currently at&lt;/span&gt;

&lt;span class="c1"&gt;// How many pixels you have scrolled vertically and horizontally within your browser tab&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scrollX&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scrollY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Some Common Window Events
&lt;/h4&gt;

&lt;p&gt;This one might be a bit confusing at first, but with the DOM, you can trigger code based on certain events.  Here's a simple example of how that works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onscroll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;stop scrolling me!!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, we are creating a function and assigning it to the &lt;code&gt;onscroll&lt;/code&gt; event, which is one of many events you can "plug in to" on this object.  Every time you scroll on the page, you will see "stop scrolling me!!" printed to your dev tools Console.&lt;/p&gt;

&lt;p&gt;We will come back to "events", but there are a few more things we need to learn first.&lt;/p&gt;

&lt;h3&gt;
  
  
  The "Document" Object
&lt;/h3&gt;

&lt;p&gt;No, not the "Document Object Model".  There is a literal object called &lt;code&gt;document&lt;/code&gt;.  Let's look at that picture again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwrgfncz79pm1cb0vshsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwrgfncz79pm1cb0vshsb.png" alt="the dom" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We just talked about the Browser, represented by the &lt;code&gt;window&lt;/code&gt; object, but now, we need to talk about that HTML Document that is being displayed within the window.  Every browser tab that you have open right now is a &lt;strong&gt;representation of&lt;/strong&gt; a single HTML document.  We can refer to this in JavaScript code via the DOM as &lt;code&gt;document&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since the HTML document is &lt;strong&gt;within&lt;/strong&gt; the browser window, it makes sense that this object is a &lt;strong&gt;property of&lt;/strong&gt; the &lt;code&gt;window&lt;/code&gt; object.  Even so, it is &lt;strong&gt;globally available&lt;/strong&gt;, which means you don't have to precede it by &lt;code&gt;window&lt;/code&gt;.  Type any of the following code into your dev tools console and it should work just fine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// These are both valid.  `document` is a property of `window` AND it is globally accessible&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseURI&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;baseURI&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While you can scroll, refresh, and manage tabs in your browser via &lt;code&gt;window&lt;/code&gt;, the &lt;code&gt;document&lt;/code&gt; object allows you to manipulate the actual &lt;strong&gt;contents of the webpage&lt;/strong&gt;.  Here are a few things you can do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add/Remove HTML elements to the page&lt;/li&gt;
&lt;li&gt;Modify existing HTML elements&lt;/li&gt;
&lt;li&gt;Add "event listeners" to HTML elements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can think of &lt;code&gt;document&lt;/code&gt; as a representation of the HTML Document.  This HTML Document is structured like a tree and believe it or not, you already have a basic understanding of this!  Let's look at a very simple HTML document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Site Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Article Heading&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text in the article&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Site created by Zach&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codepen.io/zg_dev/pen/PobopPy"&gt;See what this HTML looks like here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we type &lt;code&gt;document&lt;/code&gt; into our console, we will get an "object representation" of the HTML code we see above (please note that if you are typing this into your Codepen console, you might see something slightly different, which is because Codepen inserts additional HTML and CSS for certain functionality of their service).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Felvg9ekj71vjsgyfwz4x.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Felvg9ekj71vjsgyfwz4x.JPG" alt="document-obj" width="600" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now compare the object in the photo above to something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;nestedProp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;i&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;am&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;an&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If these two "objects" look different to you, that is good, because they are different.  While the HTML &lt;code&gt;document&lt;/code&gt; object appears to have properties similar to our good 'ole JavaScript object above, they work a bit differently.&lt;/p&gt;

&lt;p&gt;This is valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;nestedProp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;i&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;am&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;an&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nestedProp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is NOT valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// TypeError: Cannot read property 'h1' of undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So... How do we access the various HTML elements that are clearly stored in the &lt;code&gt;document&lt;/code&gt; object??&lt;/p&gt;

&lt;h3&gt;
  
  
  The "DOM Tree"
&lt;/h3&gt;

&lt;p&gt;Like we learned about before, the DOM is not a programming language, and it's not actually part of native JavaScript.  It is a "model" for an HTML Document.  Within that "model", we have "branches" and "leaves" just like a tree.  Translated into programming-speak, we call each of these branches and leaves "Nodes".  And no, this has nothing to do with NodeJS (a server-side JavaScript runtime we will be working with soon).&lt;/p&gt;

&lt;p&gt;Here is our HTML document from earlier with a few additions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Site Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Article Heading&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text in the article&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some more text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Site created by Zach&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's how we draw this in "DOM Tree" format:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F15kl8cgv1e8pxdg4qzrf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F15kl8cgv1e8pxdg4qzrf.jpg" alt="dom tree visual" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To effectively use the DOM via JavaScript, you should think of these "Nodes" like you would an ancestral hierarchy.  You've got children, siblings, parents, grandparents, and great-grandparents.  For example, all the &lt;code&gt;li&lt;/code&gt; tags within the &lt;code&gt;ul&lt;/code&gt; tag are siblings because they are at the same level in the hierarchy.  Likewise, the &lt;code&gt;p&lt;/code&gt; tags in the &lt;code&gt;div&lt;/code&gt; with the &lt;code&gt;main-body&lt;/code&gt; class are siblings.  &lt;code&gt;Body&lt;/code&gt; is the child of &lt;code&gt;HTML&lt;/code&gt; while both of the &lt;code&gt;div&lt;/code&gt; nodes are children of the &lt;code&gt;Body&lt;/code&gt; node.&lt;/p&gt;

&lt;p&gt;The above picture is a simplified view.  Each "Node" has unique characteristics, and there are a couple common node types (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType"&gt;here's a comprehensive list&lt;/a&gt;):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Element Nodes&lt;/li&gt;
&lt;li&gt;Text Nodes&lt;/li&gt;
&lt;li&gt;Attribute Nodes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'm going to bring back a diagram that you've probably seen before:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdlfbnxq9inahuhwa6nle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdlfbnxq9inahuhwa6nle.png" alt="html element" width="400" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's relate this to these "Nodes".&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt; tag is an "Element Node".  The &lt;code&gt;class="some-class"&lt;/code&gt; is an "Attribute Node".  The &lt;code&gt;Content&lt;/code&gt; value is a "Text Node".  Here, I'll prove it to you by creating this exact element in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create empty containers for each node type&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;elementNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTextNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;attributeNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elementNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;textNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Content"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;attributeNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// class=""&lt;/span&gt;

&lt;span class="c1"&gt;// Start constructing the HTML element&lt;/span&gt;
&lt;span class="c1"&gt;// Currently, our element is:  &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;elementNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;textNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Currently, our element is: &amp;lt;p&amp;gt;Content&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;attributeNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some-class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;elementNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttributeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;attributeNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Currently, our element is: &amp;lt;p class="some-class"&amp;gt;Content&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elementNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// This inserts our new HTML element at the bottom of whatever webpage you are currently on (try it out!)&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elementNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congrats!  We just recreated an HTML element with JavaScript!  I used some API methods that we haven't talked about, but hopefully you can see what is happening here in a general sense.  For example, &lt;code&gt;appendChild()&lt;/code&gt; will take an existing node and insert it between another node.&lt;/p&gt;

&lt;p&gt;What is the point of doing this though?  I can think of a few examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user creates a calendar event and you need to display it in an existing webpage&lt;/li&gt;
&lt;li&gt;A user adds an item to their todo app&lt;/li&gt;
&lt;li&gt;A user creates a post on facebook&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these actions require HTML to be created on the fly (via JavaScript).&lt;/p&gt;

&lt;p&gt;Now that we have covered some basics of the DOM, let's see how we can use it.  Please know that in the following example, we will not be covering everything there is to know about the DOM API.  As I mentioned earlier, the goal is to get acquainted with the DOM and understand how and why it is used; not master it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A DOM Example
&lt;/h2&gt;

&lt;p&gt;Now that you have a baseline understanding of how the DOM works, let's put it in action!  Let's take a look at that HTML document from earlier:&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/LYRoVKO"&gt;Basic HTML Document&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/LYRoVKO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's say our objective is to add a line of text (i.e. a &lt;code&gt;p&lt;/code&gt; element with some text in it) every time we click the button. Here are the steps we must take:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find a way to identify the &lt;code&gt;button&lt;/code&gt; HTML element using the DOM API&lt;/li&gt;
&lt;li&gt;Register a "click event" on this HTML element (i.e. tell it what to do when it is clicked)&lt;/li&gt;
&lt;li&gt;Write a function that will add a &lt;code&gt;p&lt;/code&gt; element to the HTML Document (DOM) every time the button is clicked&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 1: Identify the button
&lt;/h3&gt;

&lt;p&gt;To identify an &lt;code&gt;Element&lt;/code&gt; type using the DOM, we have several ways of doing this.  First, let me show you what the HTML looks like for the button above, because without seeing it, you cannot effectively identify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"btn-1"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"my-btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;CLICK ME&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's walk through this.  The &lt;code&gt;id&lt;/code&gt; attribute is a &lt;em&gt;global&lt;/em&gt; HTML attribute that can be used on ANY type of HTML element.  I have assigned &lt;code&gt;btn-1&lt;/code&gt; as the ID for this element, but you could have named it anything you want.  You could even name it &lt;code&gt;my-btn&lt;/code&gt;; the same exact name given to the &lt;code&gt;class&lt;/code&gt; attribute, which is also a &lt;em&gt;global&lt;/em&gt; attribute available to all HTML elements.&lt;/p&gt;

&lt;p&gt;We as the developer have assigned this button HTML element an ID and a class, which means we have many ways to identify it.  The first way we can identify this is the most generic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "&amp;lt;button id='btn-1' class='my-btn'&amp;gt;CLICK ME&amp;lt;/button&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we are using the &lt;code&gt;querySelector()&lt;/code&gt; built-in method and selecting based on the &lt;strong&gt;tag name&lt;/strong&gt; (&lt;code&gt;button&lt;/code&gt;) of the element, which will &lt;strong&gt;return the &lt;em&gt;first&lt;/em&gt; occurrence&lt;/strong&gt; of an HTML tag in the HTML document.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector"&gt;Here, you can learn more about this method.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is no problem with this method in our HTML example because we only have 1 button in the entire HTML document!  But if later, we added another button, this method of selection will cause us problems because we are not being specific enough.  Here's a better way to identify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-btn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// HTMLCollection [button#btn-1.my-btn, btn-1: button#btn-1.my-btn]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But wait a second... When using this method, we are not returned a single element!  That is because in HTML, &lt;strong&gt;you can assign a single class name to multiple HTML elements&lt;/strong&gt;.  Therefore, the &lt;code&gt;getElementsByClassName()&lt;/code&gt; will return an &lt;code&gt;HTMLCollection&lt;/code&gt; type, which is basically a fancy Array of &lt;code&gt;HTMLElement&lt;/code&gt; types.  That's probably not what we're looking for here since we only want to identify a single button.&lt;/p&gt;

&lt;p&gt;Read more about &lt;code&gt;getElementsByClassName()&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's try another way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// "&amp;lt;button id='btn-1' class='my-btn'&amp;gt;CLICK ME&amp;lt;/button&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ahhhh, that's better!  Unlike the &lt;code&gt;class&lt;/code&gt; attribute, you can only assign an ID to &lt;strong&gt;one&lt;/strong&gt; element within the document.  This would be INVALID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Button 1&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Button 2&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We CANNOT have two button elements that both have an ID of &lt;code&gt;btn&lt;/code&gt;!  So going back to our &lt;code&gt;getElementById()&lt;/code&gt; method, we know that we are being &lt;strong&gt;specific&lt;/strong&gt; AND we will only be searching for a single HTML element within the document.&lt;/p&gt;

&lt;p&gt;But to this point, I've been leading you in unnecessary directions.  We could have modified our first method, &lt;code&gt;querySelector()&lt;/code&gt; to identify this button by its tag, class, or ID!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Get the first occurrence of &amp;lt;button&amp;gt;&amp;lt;/button&amp;gt; within the HTML document&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Get the first occurrence of an HTML element that has a class of "my-btn" in the HTML document&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.my-btn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Get the HTML element that has an ID of "btn-1"&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice anything in this code above?  I do.  It looks like we are adding in &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;#&lt;/code&gt; before the identifier to look for a class and ID respectively.  Keep this in mind, you'll see it again when we start talking about CSS in the next lesson.&lt;/p&gt;

&lt;p&gt;While all three of these methods will return us the same result for this specific HTML document, that will not always be the case.  Remember, be as specific as possible when identifying HTML elements.&lt;/p&gt;

&lt;p&gt;Below, I have written all the ways we could identify that button in our HTML.  The first couple methods will return you an individual &lt;code&gt;HTMLElement&lt;/code&gt; while the second section will return an &lt;code&gt;HTMLCollection&lt;/code&gt; (again, just a fancy Array of &lt;code&gt;HTMLElement&lt;/code&gt; types).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Will return a single HTML Element&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.my-btn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Will return an HTMLCollection (multiple HTML elements stored in an Array)&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-btn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Will return a NodeList (very similar to HTMLCollection)&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.my-btn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know we haven't discussed &lt;code&gt;HTMLCollection&lt;/code&gt;, &lt;code&gt;NodeList&lt;/code&gt;, etc. yet, but stick with me.  Now that we have our button identified, let's do something cool with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Register a "click" event on the button
&lt;/h3&gt;

&lt;p&gt;C'mon Zach, you're teaching me ANOTHER new concept?? &lt;/p&gt;

&lt;p&gt;I know, this is a lot.  But we are about to talk about something called "event handling", which is a big part of programming front-end applications.  "Events" are not specific to front-end programming though; you will soon learn that events are a huge part of programming in general.&lt;/p&gt;

&lt;p&gt;In front-end programming, an "event" is &lt;strong&gt;something that occurs as a RESULT of a user action&lt;/strong&gt;.  Here are some examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user hovers their mouse over an HTML element (like a button)&lt;/li&gt;
&lt;li&gt;A user scrolls down to read the rest of an article&lt;/li&gt;
&lt;li&gt;A user clicks a button&lt;/li&gt;
&lt;li&gt;A user starts typing into an &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; field&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many more events that can occur, but if I had to pick the most common one based on my experience, it would be a "click" event.&lt;/p&gt;

&lt;p&gt;But how do we work with these "events"?&lt;/p&gt;

&lt;p&gt;So far, you know how we can identify a single HTML element within the HTML document by using the DOM.  Once you have identified that element, you can assign it to a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hint:&lt;/strong&gt; within the Codepen editor for this HTML example, you can right-click and "Inspect Element" to get to the console still.  I suggest doing so and following along here!&lt;/p&gt;

&lt;p&gt;The variable &lt;code&gt;myButton&lt;/code&gt; now represents an &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element"&gt;Element&lt;/a&gt;, which has properties, methods, and events attached to it.  I suggest you take a look at each for a minute or two:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element#properties"&gt;Element properties&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element#methods"&gt;Element methods&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element#events"&gt;Element events&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, we have a really powerful JavaScript object that we can use to make our HTML document come to life!&lt;/p&gt;

&lt;p&gt;There are two ways that we can register an "event listener" on this specific HTML element.&lt;/p&gt;

&lt;p&gt;Here's the first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myButton = document.querySelector('#btn-1');

// eventObj is automatically passed as an argument to this callback function 
function respondToClick(eventObj) {
  const randomNum = Math.floor(Math.random() * 100);
  console.log('The random number is: ' + randomNum);
}

// Pass in a callback function for this click event
myButton.addEventListener('click', respondToClick);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the second:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myButton = document.querySelector('#btn-1');

// eventObj is automatically passed as an argument to this callback function 
function respondToClick(eventObj) {
  const randomNum = Math.floor(Math.random() * 100);
  console.log('The random number is: ' + randomNum);
}

// Pass in a callback function for this click event
myButton.onclick = respondToClick;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead, paste these code snippets (one at a time of course) in the JavaScript section of this Codepen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/coVbzQOyMaOU4ZuG5Q/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/coVbzQOyMaOU4ZuG5Q/giphy.gif" alt="" width="480" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is nothing remarkable about what we are doing here.  We select an element from our HTML document using the DOM (&lt;code&gt;document.querySelector()&lt;/code&gt;), write a function that prints a random number to the console, and then instruct our HTML element, &lt;code&gt;myButton&lt;/code&gt; to respond to click events by running that function, &lt;code&gt;respondToClick()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You might ask, how did I know to pass in &lt;code&gt;click&lt;/code&gt; to the &lt;code&gt;addEventListener()&lt;/code&gt; method, or how did I know to use &lt;code&gt;onclick&lt;/code&gt; in the second version?&lt;/p&gt;

&lt;p&gt;The easiest way to learn about events is by reading through the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Events"&gt;Events Reference page on MDN&lt;/a&gt;.  I suggest clicking around (no pun intended) in that documentation for a few minutes to get a sense of what events are available to you in the browser as a developer.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Add an element to the HTML Document Programmatically
&lt;/h3&gt;

&lt;p&gt;We're almost there!  We now just have to adapt our &lt;code&gt;respondToClick&lt;/code&gt; function so that it will add a new &lt;code&gt;p&lt;/code&gt; element to the DOM every time the button is clicked.  We don't need to get fancy; let's just add a &lt;code&gt;p&lt;/code&gt; tag with the same text that we are currently printing to the Console.&lt;/p&gt;

&lt;p&gt;In order to do this, we'll need to use some DOM methods that help us &lt;strong&gt;modify&lt;/strong&gt; the existing HTML document and its elements.  Let's take a look at the reference for the &lt;code&gt;document&lt;/code&gt; object.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document"&gt;You can find it here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember, &lt;code&gt;document&lt;/code&gt; is the "global" object and represents the "entry point into the web page's content".  Since our HTML document is rather small in this case, we can use this global object to insert &lt;code&gt;p&lt;/code&gt; tags at the end of the content.  Here are &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document#methods"&gt;the methods&lt;/a&gt; we'll need to make this happen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Document.createElement()&lt;/code&gt; - Allows us to create a new &lt;code&gt;p&lt;/code&gt; HTML element (i.e. it will initialize something like &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Document.createTextNode()&lt;/code&gt; - Allows us to create the text which we will insert into our new element&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Node.appendChild()&lt;/code&gt; - Allows us to add our new "text node" to our new paragraph element (&lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#btn-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// eventObj is automatically passed as an argument to this callback function &lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;respondToClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;eventObj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Generate some random text&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The random number is: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;randomNum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Initialize a `p` tag - &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Initialize some text content&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newTextNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTextNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pContent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Insert the text content between &amp;lt;p&amp;gt; and &amp;lt;/p&amp;gt; from the element we initialized earlier&lt;/span&gt;
  &lt;span class="nx"&gt;newElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTextNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Insert the new `p` element at the end of the HTML &amp;lt;body&amp;gt;&amp;lt;/body&amp;gt; tag&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Pass in a callback function for this click event&lt;/span&gt;
&lt;span class="nx"&gt;myButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;respondToClick&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, when we click the button, it inserts a new element to the HTML document!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/6jtmpjcBdhvABDSYwX/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/6jtmpjcBdhvABDSYwX/giphy.gif" alt="" width="480" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see &lt;a href="https://codepen.io/zg_dev/pen/rNMgOaj?editors=1011"&gt;the working Pen here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Navigating an HTML Document
&lt;/h2&gt;

&lt;p&gt;Let's return to the HTML document we looked at previously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Site Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Article Heading&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text in the article&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some more text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;List item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Site created by Zach&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example we just walked through was wide, but not deep.  While we covered how to select, insert, and respond to events, we did not talk about techniques for parsing through an HTML document.  For example, how would we...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select and modify the second item of the list?&lt;/li&gt;
&lt;li&gt;Add a fourth element to the list?&lt;/li&gt;
&lt;li&gt;Add another &lt;code&gt;p&lt;/code&gt; element after the second &lt;code&gt;p&lt;/code&gt; element?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To accomplish this, we need to remember that every HTML document is just a "tree".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl3ii9gaz4bzxe3nusr6f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl3ii9gaz4bzxe3nusr6f.jpg" alt="dom tree visual" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Furthermore, if we connect the dots a little bit, we can recognize that "sibling" nodes in an HTML document might make sense to store in an Array.  Let's see that in action.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selecting "children" elements
&lt;/h3&gt;

&lt;p&gt;Our first task is to modify the second element of our list.  To do this, I'm thinking we do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find a way to identify the list within the HTML document&lt;/li&gt;
&lt;li&gt;Find a way to select an individual element from the list&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Based on what we have talked about, I would not expect you to know how to do this yet.  The purpose here is to get you into the "DOM mindset" and expose you to some common ways that you might use the DOM API in your projects.&lt;/p&gt;

&lt;p&gt;So let's start by identifying that list within our HTML document.  &lt;strong&gt;There are MANY ways that we can do so&lt;/strong&gt;, but I'll start with the most logical one.&lt;/p&gt;

&lt;p&gt;Since we only have one &lt;code&gt;ul&lt;/code&gt; tag in the entire document, we can use a basic query selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As with any tutorial, my goal is to make you self sufficient, so the first question we should be asking here is, "what type of node is this?".  With the DOM, it is often tough to know what type of node you are dealing with whether that be a text node, attribute node, or element node.  If at any point you don't know what you're working with, here's how you figure it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nodeType&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the &lt;code&gt;nodeType&lt;/code&gt; property that exists on ALL nodes.  But what does &lt;code&gt;1&lt;/code&gt; represent?  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#node_type_constants"&gt;Here's a table that tells you&lt;/a&gt;.  In this case, we are working with an &lt;code&gt;Element&lt;/code&gt;.  From this information, we can visit the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Element"&gt;Element documentation&lt;/a&gt; and take a look at some of the properties and methods available to us.&lt;/p&gt;

&lt;p&gt;If you visit the &lt;code&gt;Element&lt;/code&gt; docs, you'll see that one of the available properties on an &lt;code&gt;Element&lt;/code&gt; node is &lt;code&gt;children&lt;/code&gt;.  Since the &lt;code&gt;li&lt;/code&gt; tags are "children" to the &lt;code&gt;ul&lt;/code&gt; "container" tag, this seems like a property that might help us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxuhl4mjxbbzgyklkmeai.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxuhl4mjxbbzgyklkmeai.JPG" alt="element children" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, it's kind of like an Array, but not quite.  Go ahead and take a look at the &lt;code&gt;HTMLCollection&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection"&gt;documentation&lt;/a&gt;.  While here, you'll notice that there is a method called &lt;code&gt;item()&lt;/code&gt;, which we can pass an "array index" to get a certain element from the &lt;code&gt;HTMLCollection&lt;/code&gt; "Array".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Remember, arrays are "zero-indexed"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondListItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have identified our element, all we have to do is &lt;strong&gt;modify it&lt;/strong&gt;.  In this case, &lt;code&gt;secondListItem&lt;/code&gt; is an &lt;code&gt;Element&lt;/code&gt; type, which has an editable property called &lt;code&gt;textContent&lt;/code&gt;.  Let's use this to change the value of the second element in our list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Remember, arrays are "zero-indexed"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondListItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;secondListItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a new value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Awesome!  We have modified the second element of HTML list.&lt;/p&gt;

&lt;p&gt;Now here's something important to remember–&lt;strong&gt;the change you just made is temporary&lt;/strong&gt;.  If you are rendering static HTML code in the browser, JavaScript cannot directly edit it.  Once you refresh the page, your second list item will return to the original value.  Knowing this, you might ask, "if the changes are temporary, what's the point?".  This is a tough question to answer at our current level of understanding, but a very good question.  The answer will reveal itself to you as we get deeper into this series, but here's my short answer–&lt;strong&gt;the user needs to see changes in real-time&lt;/strong&gt;.  If your user has to wait 2 seconds or even refresh the page every time he/she takes an action, the user experience will be poor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating elements
&lt;/h3&gt;

&lt;p&gt;Our next goal is to add a fourth element to our list.  Remember, our &lt;code&gt;ul&lt;/code&gt; list is an &lt;code&gt;Element&lt;/code&gt;, which has properties and methods that we can use.  But if you read through its documentation, you probably won't find anything that helps us here...&lt;/p&gt;

&lt;p&gt;And this brings up a very important (but kind of confusing) concept–inheritance.  Remember how I talked about how everything in the "DOM Tree" is a "node"?  Well, I meant it.  It doesn't matter whether we are working with an &lt;code&gt;Element&lt;/code&gt;, &lt;code&gt;Attribute&lt;/code&gt;, or &lt;code&gt;Text&lt;/code&gt;.  They all "inherit" from the &lt;code&gt;Node&lt;/code&gt; type, which means they all can use the properties and methods on the &lt;code&gt;Node&lt;/code&gt; type along with their own properties and methods.  This is an OOP (object-oriented programming) concept and can be quite confusing.  We will learn more about this later in the series.&lt;/p&gt;

&lt;p&gt;Anyways, since there is nothing useful to us on the &lt;code&gt;Element&lt;/code&gt; type, let's take at the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node"&gt;documentation for the Node type&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It has a method called &lt;code&gt;appendChild()&lt;/code&gt; that will help us add that fourth list item!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs3z8aukkco11n6z8bpf4.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs3z8aukkco11n6z8bpf4.JPG" alt="append child" width="591" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that the parameter it specifies, &lt;code&gt;aChild&lt;/code&gt;, is a node.  In our case, we probably want to create another &lt;code&gt;li&lt;/code&gt; element, which we can do with the &lt;code&gt;document.createElement()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Creates &amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newListItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Creates &amp;lt;li&amp;gt;Fourth list item&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;newListItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fourth list item&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Adds the new element to the existing list&lt;/span&gt;
&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newListItem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're really paying attention to this article closely, you might remember that when we created a new element earlier, we did something like this to add the text to the element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newListItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTextNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fourth list item&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;newListItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;textNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just another way to solve the problem.  You'll learn that with the DOM and programming in general, there are ALWAYS several ways to achieve the same thing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding elements between other elements
&lt;/h3&gt;

&lt;p&gt;Our final objective is to add the following &lt;code&gt;p&lt;/code&gt; element after the first &lt;code&gt;p&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some inserted text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So... What element do we need to select?  The Node type has a method called &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore"&gt;insertBefore()&lt;/a&gt; which we can use to insert our &lt;code&gt;p&lt;/code&gt; element before the second &lt;code&gt;p&lt;/code&gt; element (hence, after the first &lt;code&gt;p&lt;/code&gt; element).&lt;/p&gt;

&lt;p&gt;Here's a problematic way to identify that second &lt;code&gt;p&lt;/code&gt; item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why is this problematic?  If you try it out, you'll realize that this selects the &lt;strong&gt;first&lt;/strong&gt; &lt;code&gt;p&lt;/code&gt; element and ONLY the first &lt;code&gt;p&lt;/code&gt; element.  Let's try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Better, but not great.  This will give us all the &lt;code&gt;p&lt;/code&gt; elements in the entire document, &lt;em&gt;including&lt;/em&gt; the one in the &lt;code&gt;&amp;lt;div class="footer"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; element.  Let's get a little bit more specific with our query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// First, select the div with a class of "main-body"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mainBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.main-body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mainBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is much better.  The &lt;code&gt;pItems&lt;/code&gt; variable will be a &lt;code&gt;NodeList&lt;/code&gt;, which is similar to &lt;code&gt;HTMLCollection&lt;/code&gt; which we looked at earlier.  We can use the &lt;code&gt;item()&lt;/code&gt; method on it to select the second &lt;code&gt;p&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// First, select the div with a class of "main-body"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mainBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.main-body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mainBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondParagraphElem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we just need to insert a new &lt;code&gt;p&lt;/code&gt; element after this selected element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Step 1: Find the element we want to insert something after&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mainBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.main-body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mainBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondParagraphElem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Step 2: Create the element we want to insert&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newElem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;newElem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some inserted text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Step 3: Insert the element&lt;/span&gt;
&lt;span class="nx"&gt;mainBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insertBefore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newElem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secondParagraphElem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll notice that the &lt;code&gt;insertBefore()&lt;/code&gt; method has two parameters.  If you &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore#syntax"&gt;read the documentation&lt;/a&gt;, you'll learn that we need to call this method on the "parent element" that we want to insert the new element in.  In this case, the "parent element" is &lt;code&gt;mainBody&lt;/code&gt; (look at the DOM Tree diagram earlier in this post).  The first parameter is the element you want to insert, which is &lt;code&gt;newElem&lt;/code&gt;.  And the second parameter is the "reference element", which represents the element you want to insert your new element before.  In this case, that is &lt;code&gt;secondParagraphElem&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want to see all of this code in action, check out this Pen I made!&lt;/p&gt;

&lt;p&gt;See the Pen &lt;a href="https://codepen.io/zg_dev/pen/PobopPy"&gt;Another Basic HTML Doc&lt;/a&gt; by Zach &lt;br&gt;
  (&lt;a href="https://codepen.io/zg_dev"&gt;@zg_dev&lt;/a&gt;) on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/zg_dev/embed/PobopPy?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The DOM is Confusing
&lt;/h2&gt;

&lt;p&gt;If you're still reading, good.  You've got the type of mind for this challenging skill we call programming.  That said, you're probably still confused with this "DOM" concept, and I don't blame you.  There is a LOT going on with the DOM and I could easily create an entire programming course on it alone.  It would take weeks to cover all of the DOM interfaces, methods, properties, and events.&lt;/p&gt;

&lt;p&gt;For that reason, we're stopping here.  My goal here was to introduce you to the DOM, so I hope I did that effectively.&lt;/p&gt;

&lt;p&gt;As we move forward through this full-stack series, you probably won't be working with the DOM a ton.  The reason?  Because front-end frameworks like Angular, React, and Vue abstract the DOM away and provide you with &lt;em&gt;easier&lt;/em&gt; ways to manipulate it.&lt;/p&gt;

&lt;p&gt;That does NOT mean learning the DOM is unimportant.  Quite the contrary!  Knowing how the DOM works and being able to use it will give you an edge on other web developers who never spent the time to learn it.&lt;/p&gt;

&lt;p&gt;So if you don't feel confident with the DOM, &lt;strong&gt;that's okay. Keep moving forward&lt;/strong&gt;.  If you can explain the basic concept of the DOM and do super basic things with it, you are in a great spot!&lt;/p&gt;

&lt;h2&gt;
  
  
  A Recap of HTML
&lt;/h2&gt;

&lt;p&gt;Remember, if we are building a house, HTML is the structure, CSS is the styling, and JavaScript is the functionality.  To me, HTML can be expressed in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static HTML&lt;/li&gt;
&lt;li&gt;Dynamic HTML&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Static HTML is what we learned in the first part of the lesson.  When you write static HTML, you are basically telling your browser, "Here's the document I want you to display, and it's never going to change".  Static HTML is all over the web.  Most blogs and writing on the web are just static HTML documents.&lt;/p&gt;

&lt;p&gt;Dynamic HTML is the second part of this lesson.  By "modeling" an HTML document, we can plug into it with JavaScript (via the DOM) and make some crazy things happen!  This is required for web apps like YouTube, Facebook, and others.  While we could use the DOM alone to bring this functionality to our apps, there are easier ways to do this (i.e. front-end frameworks like Angular, React, Vue, etc.).&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing "Semantic" HTML (the new parts)
&lt;/h2&gt;

&lt;p&gt;The last thing I want to cover in this crash course on HTML is something that is not &lt;em&gt;required&lt;/em&gt; for you at this stage in your journey, but helpful to know about.&lt;/p&gt;

&lt;p&gt;Let's go back to that house analogy.  If HTML is the "structure" of the house, what does that include?  I'm no home-builder, but to build a house, you need more than just 2x4s.  You need multiple types of wood, and additionally, other materials for certain sections of the house you are building.&lt;/p&gt;

&lt;p&gt;HTML is no different.  While we &lt;em&gt;could&lt;/em&gt; build our HTML documents with a bunch of &lt;code&gt;div&lt;/code&gt; elements, that is not "semantic".  In other words, we are not conveying what the elements are meant to contain effectively.&lt;/p&gt;

&lt;p&gt;There are many HTML tags that I did not show you during the first part of this post to avoid over-complicating the discussion.  But from a semantic standpoint, it is "best practice" to use HTML elements that convey what the elements represent in your document.&lt;/p&gt;

&lt;p&gt;Most of the elements I am about to show you were introduced in the HTML5 standard, which is the newest standard of HTML.  Consider the following HTML document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My Blog&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"An example blog site"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"author"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Zach Gollwitzer"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"css/styles.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Blog&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sidebar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
        Some sidebar offering here
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"article-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text for the blog post&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"article-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text for the blog post&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"article-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text for the blog post&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some footer text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Copyright, 2021&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"js/scripts.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we added some CSS (styling) to this HTML document, we'd have a blog page with a navigation bar at the top, a sidebar on the right, a list of blog posts in the main area, and a footer at the bottom.  &lt;a href="https://www.thediygolfer.com/10-tips-for-breaking-90-faster/"&gt;Here's my golf blog&lt;/a&gt; as an example of the layout I'm describing.&lt;/p&gt;

&lt;p&gt;The HTML document above is &lt;strong&gt;fine&lt;/strong&gt;.  It works perfectly.  But as you can see, we're using a lot of &lt;code&gt;div&lt;/code&gt; elements despite the fact that each section of this document has a different purpose.  When I say "semantic HTML", I'm referring to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My Blog&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"An example blog site"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"author"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Zach Gollwitzer"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"css/styles.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Blog&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sidebar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
        Some sidebar offering here
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;main&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"article-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text for the blog post&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"article-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text for the blog post&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;article&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"article-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some text for the blog post&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;footer&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Some footer text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Copyright, 2021&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"js/scripts.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can you see the difference?  In the second version, I'm using the following HTML tags that we haven't covered before:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;nav&amp;gt;&amp;lt;/nav&amp;gt;&lt;/code&gt; - &lt;a href="https://developer.mozilla.org/en-us/docs/Web/HTML/Element/nav"&gt;here is the documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;section&amp;gt;&amp;lt;/section&amp;gt;&lt;/code&gt; - &lt;a href="https://developer.mozilla.org/en-us/docs/Web/HTML/Element/section"&gt;here is the documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;main&amp;gt;&amp;lt;/main&amp;gt;&lt;/code&gt; - &lt;a href="https://developer.mozilla.org/en-us/docs/Web/HTML/Element/main"&gt;here is the documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;article&amp;gt;&amp;lt;/article&amp;gt;&lt;/code&gt; - &lt;a href="https://developer.mozilla.org/en-us/docs/Web/HTML/Element/article"&gt;here is the documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;footer&amp;gt;&amp;lt;/footer&amp;gt;&lt;/code&gt; - &lt;a href="https://developer.mozilla.org/en-us/docs/Web/HTML/Element/footer"&gt;here is the documentation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Furthermore, tags like &lt;code&gt;strong&lt;/code&gt; and &lt;code&gt;em&lt;/code&gt; that I introduced to you at the beginning of the post work fine, but in the new HTML5 standard, are not technically "recommended".  The idea with the newest HTML standard is that each HTML tag should represent &lt;strong&gt;intent, not style&lt;/strong&gt;.  For example, the &lt;code&gt;section&lt;/code&gt; tag indicates that everything within it is part of an independent section of the webpage.  You shouldn't use this tag for any other purpose.&lt;/p&gt;

&lt;p&gt;Now if we zoom out a bit, these details that I'm introducing should not be at the top of your priority list.  These are details that you'll focus on down the road when you are trying to master your craft.&lt;/p&gt;

&lt;p&gt;I bring them up here so that you are not surprised when you see them in another developer's code.&lt;/p&gt;

&lt;p&gt;Remember, the documentation is your friend!  If you stumble upon something you haven't seen before, just look it up!  If you don't know what a certain tag should be used for, read the documentation page for it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally, your HTML Challenge
&lt;/h2&gt;

&lt;p&gt;From this point forward, our lesson challenges are going to be a lot more fun than the previous lessons. Rather than writing plain JavaScript code, all challenges from here forward will combine HTML, CSS, and JavaScript. Not only that, but you'll now have something to share with the world!&lt;/p&gt;

&lt;p&gt;When you complete these challenges, be sure to share them on Twitter with the hashtag, #100DaysOfCode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And don't forget, we call this a "challenge" because it is very challenging.  You should not be able to complete this without some additional research!&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge Instructions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://codepen.io/zg_dev/pen/xxRbrBw"&gt;Fork this Codepen&lt;/a&gt; to your account (click the "Fork" button in the bottom right corner of the browser window)&lt;/li&gt;
&lt;li&gt;Create this:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/qwUeoBBmQUW1hLxXRn/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/qwUeoBBmQUW1hLxXRn/giphy.gif" alt="random joke" width="480" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  User Stories
&lt;/h3&gt;

&lt;p&gt;A "user story" is something you'll use often in programming.  It defines &lt;em&gt;how&lt;/em&gt; a user should interact with your application and is commonly used during the requirements gathering phase of application development.  Below are the user stories for this challenge.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user should be able to click buttons on the right side of the screen to generate a random meme, joke, quote, or riddle&lt;/li&gt;
&lt;li&gt;Only one piece of content should show at a time.  For example, if the user clicks "Show a meme" and there is a quote showing already, the application should remove the quote and show a random meme.&lt;/li&gt;
&lt;li&gt;Content should be displayed under the appropriate heading (i.e. a joke should not show up under the memes heading)&lt;/li&gt;
&lt;li&gt;When showing a random riddle, the answer should never be revealed without the user explicitly clicking the "Reveal Riddle Answer" button on the right.&lt;/li&gt;
&lt;li&gt;If a user clicks "Reveal Riddle Answer" and there is no riddle, an alert should let them know they need to generate a riddle first&lt;/li&gt;
&lt;li&gt;If a user clicks "Reveal Riddle Answer" and the answer is already revealed, an alert should let them know that the answer is already revealed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Some Hints
&lt;/h3&gt;

&lt;p&gt;As I said, this programming challenge is tough.  You'll need to look things up on Google.  Here are some hints to help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;div&lt;/code&gt; element with a unique id or class name can be a great way to establish a "container" for future content (even before that content exists)&lt;/li&gt;
&lt;li&gt;You might need to use the &lt;a href="https://developer.mozilla.org/en-us/docs/Web/API/HTMLElement/hidden"&gt;HTMLElement.hidden property&lt;/a&gt; for the riddles&lt;/li&gt;
&lt;li&gt;There is no "perfect" solution.  Solve it how you think makes sense&lt;/li&gt;
&lt;li&gt;The starter has some code already written for you.  Read it and see what it is doing!  You should be able to solve this without adding any additional functions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Solution
&lt;/h3&gt;

&lt;p&gt;If you want to see how I implemented it, you can either...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=deqOja994Z8"&gt;Watch the YouTube video of me solving it&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codepen.io/zg_dev/pen/abBzvXv"&gt;See my Codepen solution&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Lesson 6 - JavaScript Built-In Functions and Objects #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Tue, 19 Jan 2021 23:45:25 +0000</pubDate>
      <link>https://dev.to/zachgoll/lesson-6-javascript-built-in-functions-and-objects-fullstackroadmap-29ke</link>
      <guid>https://dev.to/zachgoll/lesson-6-javascript-built-in-functions-and-objects-fullstackroadmap-29ke</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=O3iR-CIufKM"&gt;See this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is part of my fullstack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first fullstack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back.  This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/zg_dev"&gt;My Twitter Profile&lt;/a&gt; - Where you can stay updated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;In the prior lessons, we covered many of the basic parts of JavaScript, and with our &lt;a href="https://www.youtube.com/watch?v=sqRk0Ly66Ps"&gt;25 code challenges&lt;/a&gt;, we even explored a few of the built-in JavaScript methods.&lt;/p&gt;

&lt;p&gt;In this lesson, I'm going to not only teach you how to read JavaScript MDN documentation but will also show you the most common built-in objects and functions that you might see as a developer.&lt;/p&gt;

&lt;p&gt;At the end, I have curated 10 code challenges that will enforce some of the concepts explained within the post.&lt;/p&gt;

&lt;p&gt;Here are the topics we will cover.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to read documentation&lt;/li&gt;
&lt;li&gt;Quick Start to Callback Functions&lt;/li&gt;
&lt;li&gt;Primitives vs. Objects (I've been lying to you in the prior lessons)&lt;/li&gt;
&lt;li&gt;Dates&lt;/li&gt;
&lt;li&gt;Regular Expressions&lt;/li&gt;
&lt;li&gt;Common String Methods&lt;/li&gt;
&lt;li&gt;Common Array Methods&lt;/li&gt;
&lt;li&gt;Math Library&lt;/li&gt;
&lt;li&gt;Error types&lt;/li&gt;
&lt;li&gt;NaN, null, undefined&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;This will be the last post in this series where we will be covering the basics of JavaScript.&lt;/strong&gt;  If at any point you would like to further your education past what we have talked about, I highly recommend &lt;a href="https://github.com/getify/You-Dont-Know-JS/tree/1st-ed"&gt;You Don't Know JavaScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are additional JavaScript concepts such as async/await, Promises, and Classes, but we will probably not be covering these until we have a foundation in the basics of HTML, CSS, and JavaScript.  I do plan on covering them, but not YET.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to read documentation
&lt;/h2&gt;

&lt;p&gt;We will start with a very important skill that you must have as a programmer.  You may have heard the saying, RTFM, which stands for "Read the f******** manual".  This is common in software engineering because &lt;strong&gt;most problems can be solved by reading documentation&lt;/strong&gt;.  And when I say "documentation", I'm just referring to the instructional guides written to explain how to use a certain framework, library, or programming language.&lt;/p&gt;

&lt;p&gt;Since we have only been exposed to JavaScript thus far, the most common source of documentation is MDN (Mozilla Developer Network).  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript"&gt;Here is the homepage for JavaScript documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The documentation for each language/framework/library will be different, but high-quality documentation usually has the following resources available to the developer.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A QuickStart or Overview guide&lt;/li&gt;
&lt;li&gt;An extended tutorial&lt;/li&gt;
&lt;li&gt;API Reference (often just called "Reference" or "API")&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Whenever I start learning a new framework, the QuickStart and tutorial(s) is a great way to learn the basics and then I lean on the API reference (along with unofficial tutorials) as needed while building my project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference"&gt;Here is the API Reference&lt;/a&gt; for the JavaScript programming language.  Since JavaScript is so widespread, there are several websites that provide an API reference, but usually, frameworks and libraries will only have one "official" set of documentation.&lt;/p&gt;

&lt;p&gt;As you scroll through JavaScript's reference, you may be confused, and that's okay.  Remember, the reference documents &lt;strong&gt;everything&lt;/strong&gt; about JavaScript.  You don't need to read it like a book.  Use it as a reference (hence the name).&lt;/p&gt;

&lt;p&gt;Let's say that you were solving &lt;a href="https://www.youtube.com/watch?v=sqRk0Ly66Ps&amp;amp;t=1833s"&gt;one of the practice problems&lt;/a&gt; from the last lesson and you wanted to know more about the &lt;code&gt;push()&lt;/code&gt; method that we use on arrays.  Here's how you get there.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference"&gt;JavaScript reference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Since &lt;code&gt;push()&lt;/code&gt; is an array method, find the Array data type and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;click on it&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Scroll down to "Instance methods" and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push"&gt;click the push method&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Read the page that explains how this method works&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step #4 is much easier said than done.  Reading documentation is hard for beginners, so let's walk through how to do it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview Section
&lt;/h3&gt;

&lt;p&gt;Let's look at an Array method called &lt;code&gt;pop()&lt;/code&gt;.  It is one of the easiest methods to learn.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop"&gt;Here is the documentation that the screenshots are from&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F26ii6vxxisq2pppld1ln.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F26ii6vxxisq2pppld1ln.JPG" alt="pop" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The documentation usually starts off with an overview of the function.  This oftentimes is the only information that you'll need.  From this overview, we can see that the &lt;code&gt;pop()&lt;/code&gt; method removes the last element of an array (i.e. modifies the original array) and returns the element that was removed.&lt;/p&gt;

&lt;p&gt;But maybe the overview section doesn't give you all the information you need.  Scroll down to the syntax section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;This section is probably the most direct way of documenting a function.  This explains to you the &lt;strong&gt;inputs&lt;/strong&gt; and &lt;strong&gt;outputs&lt;/strong&gt; that the functions receives and returns respectively.  Once you get good at reading documentation and have a familiarity with programming in general, this section is usually all that you will need to start using a given function.&lt;/p&gt;

&lt;p&gt;Let's continue with the &lt;code&gt;array.pop()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjiouxdxalrdo87p42kgx.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjiouxdxalrdo87p42kgx.JPG" alt="pop" width="587" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By looking at this, we can infer that the &lt;code&gt;pop()&lt;/code&gt; method does not take any parameters and returns the value of the array that was removed.&lt;/p&gt;

&lt;p&gt;Unlike the overview section, this also notes that if you use the &lt;code&gt;pop&lt;/code&gt; method on an empty array, it will return &lt;code&gt;undefined&lt;/code&gt;.  You can go ahead and try this out in your dev tools console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emptyArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;emptyArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at another method that is a bit more complex.  Here is the &lt;code&gt;array.join()&lt;/code&gt; method's "Syntax" section (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"&gt;link to page&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwyz10d2wsut6bwjwx02n.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwyz10d2wsut6bwjwx02n.JPG" alt="join method" width="716" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike the &lt;code&gt;array.pop()&lt;/code&gt; method, this one has a single, optional parameter.  We can tell that the parameter is optional because &lt;code&gt;[separator]&lt;/code&gt; has &lt;code&gt;[]&lt;/code&gt; surrounding it.  Additionally, in the parameters section, it denotes that this is optional.&lt;/p&gt;

&lt;p&gt;Looking at the return value, you can see that this method returns a String value with all the elements of the given array joined together.  It also notes that if you try to use this method on an empty array, the return value will be an empty string.&lt;/p&gt;

&lt;p&gt;Here's how you would translate this documentation into code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// First, let's test it without any parameter (since params are optional)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "hello,world"&lt;/span&gt;

&lt;span class="c1"&gt;// Now, let's add a parameter in there&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "hello world"&lt;/span&gt;

&lt;span class="c1"&gt;// And finally, let's try it on an empty array which according to&lt;/span&gt;
&lt;span class="c1"&gt;// the documentation, should return an empty string&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;empty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

&lt;span class="nx"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// ""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the syntax section of the &lt;code&gt;push()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F61xkm1rgya7hf0xc2k5i.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F61xkm1rgya7hf0xc2k5i.JPG" alt="push method" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start with this part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;element1&lt;/span&gt;&lt;span class="p"&gt;[,&lt;/span&gt; &lt;span class="p"&gt;...[,&lt;/span&gt; &lt;span class="nx"&gt;elementN&lt;/span&gt;&lt;span class="p"&gt;]]])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What on earth is going on here?!  What this is trying to explain is the function's parameters.  First, the brackets &lt;code&gt;[]&lt;/code&gt; indicate that arguments are optional (not to be confused with the array bracket syntax we learned earlier).  In this case, if you don't pass an argument, your array will remain unchanged.  Second, you'll notice the &lt;code&gt;...&lt;/code&gt; which tell us that this method takes an infinite number of arguments.&lt;/p&gt;

&lt;p&gt;As we look at the return value, we can see that it returns the length of the &lt;strong&gt;new&lt;/strong&gt; array after the push operation.  Take a look at the code below and guess what the &lt;code&gt;result&lt;/code&gt; variable equals.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No, &lt;code&gt;result&lt;/code&gt; does not equal &lt;code&gt;[1, 2, 3, 4, 5, 6, 7, 8, 9]&lt;/code&gt; as you might expect.  The &lt;code&gt;result&lt;/code&gt; variable equals &lt;code&gt;9&lt;/code&gt; (the length of the new array) and &lt;code&gt;arr&lt;/code&gt; equals the new array.&lt;/p&gt;

&lt;p&gt;You might ask–well we assigned this with the &lt;code&gt;const&lt;/code&gt; keyword, so how can we re-assign it?!  I don't want to get too far off topic, so &lt;a href="https://stackoverflow.com/a/45597013/7437737"&gt;go read this&lt;/a&gt; if you're curious.&lt;/p&gt;

&lt;p&gt;Okay, let's look at one more example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7xpzbp647q4psrbp10z3.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7xpzbp647q4psrbp10z3.JPG" alt="includes method" width="800" height="821"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, you'll see that this function has two parameters.  The &lt;code&gt;valueToFind&lt;/code&gt; parameter is required while the &lt;code&gt;fromIndex&lt;/code&gt; is optional (you'll notice at the bottom of its description, it says that it defaults to 0).&lt;/p&gt;

&lt;p&gt;The return value is a boolean, which indicates whether &lt;code&gt;valueToFind&lt;/code&gt; exists in the &lt;code&gt;arr&lt;/code&gt; that we are searching in.&lt;/p&gt;

&lt;p&gt;Using just this information above, we can try out a few different ways of using this method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false, since we start searching at index 1 and orange is index 0&lt;/span&gt;
&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// false, need a parameter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Examples, Specifications, Browser Compatibility
&lt;/h3&gt;

&lt;p&gt;The remaining sections you will see in the documentation for a specific method like the ones above are useful, but not always required.&lt;/p&gt;

&lt;p&gt;The examples section is self-explanatory.  The specifications section will show you where in the ECMAScript standards you will find this method (remember from lesson 2?).&lt;/p&gt;

&lt;p&gt;And finally, the browser compatibility will show you which browsers this function will work correctly in.  If you look at the &lt;code&gt;arr.includes()&lt;/code&gt; method, it won't work in Internet Explorer, so if you are building an application that needs to work in IE (say in a large corporation), you should NOT use the &lt;code&gt;arr.includes()&lt;/code&gt; method.  Starting out, I wouldn't focus on browser compatibility though–learning to code is hard enough!&lt;/p&gt;

&lt;h2&gt;
  
  
  Callback Functions: Confusing, but necessary
&lt;/h2&gt;

&lt;p&gt;Before we start exploring the different built-in JavaScript functions, you need at least a general understanding of callback functions.&lt;/p&gt;

&lt;p&gt;No, these are not a different type of writing a function.  They represent a different way of &lt;strong&gt;using&lt;/strong&gt; a function.&lt;/p&gt;

&lt;p&gt;Here is some really confusing code that I hope you will have a basic understanding of 5 minutes from now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;someNumber&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This also could have been simplified to the following (does the same exact thing):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately for the beginner, the second block of code is what you'll see most often because it is more succinct.&lt;/p&gt;

&lt;p&gt;Let's walk through the first code block with some comments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;someNumber&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// in this example result === 20&lt;/span&gt;

  &lt;span class="c1"&gt;// In this example, shouldCall is `true`, so we do reach the callback&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// In this example, `callback` represents `myCallback` from above&lt;/span&gt;
    &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Since `result` was re-assigned by the callback function, returns 40&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns 40&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could have gotten the same result by just calling &lt;code&gt;myCallback&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns 40&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is nothing special about &lt;code&gt;myCallback&lt;/code&gt;.  It is just a function, but instead of calling this function separately, we can ask &lt;code&gt;mainFunction&lt;/code&gt; to do it for us!  Zooming in on &lt;code&gt;result = callback(randomNumber)&lt;/code&gt;, you can see that we are taking the value of &lt;code&gt;randomNumber&lt;/code&gt;, which is &lt;code&gt;20&lt;/code&gt; in this case and passing it in as an argument to &lt;code&gt;callback&lt;/code&gt;.  What is &lt;code&gt;callback&lt;/code&gt;?  It's the function we pass in as an argument.&lt;/p&gt;

&lt;p&gt;So let's take the function we defined just a second ago, &lt;code&gt;myCallback&lt;/code&gt;, and pass it into &lt;code&gt;mainFunction&lt;/code&gt; as an argument!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And of course, you don't have to define &lt;code&gt;myCallback&lt;/code&gt; as a separate function.  You could do it as an anonymous function OR an arrow function.  All of these produce the same result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;someNumber&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Different methods of using callbacks below 👇
 */&lt;/span&gt;

&lt;span class="c1"&gt;// Using pre-defined function as a callback&lt;/span&gt;
&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Using anonymous function as a callback&lt;/span&gt;
&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Using an arrow function as a callback&lt;/span&gt;
&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Using an arrow function with abbreviated notation&lt;/span&gt;
&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Using an arrow function with even MORE abbreviation&lt;/span&gt;
&lt;span class="nf"&gt;mainFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  So... What's the point of a callback?
&lt;/h3&gt;

&lt;p&gt;There are two advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reusability of functions&lt;/li&gt;
&lt;li&gt;Asynchronous programming&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Callbacks enable reusability
&lt;/h4&gt;

&lt;p&gt;Let's look at a built-in JavaScript function called &lt;code&gt;arr.map()&lt;/code&gt;.  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;You can find the documentation here&lt;/a&gt;, and I encourage you to try and figure it out before we start talking about it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// itemFromArray represents a single value from the array above such as `2`&lt;/span&gt;
&lt;span class="c1"&gt;// Hint: the arr.map() function is similar to looping through an array like we did in the challenge problems from lesson 5&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myCustomMapOperation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;itemFromArray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;itemFromArray&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myCustomMapOperation&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [4, 8, 12, 16]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, I am passing &lt;code&gt;myCustomMapOperation&lt;/code&gt; as my "callback" function into the built-in &lt;code&gt;arr.map()&lt;/code&gt; JavaScript function.  This custom callback function that I wrote will double the values in an array.&lt;/p&gt;

&lt;p&gt;But what if my array was filled with string values and I wanted to make a new array that only contains the first letter of each string?  Don't I have to go search for another built-in JavaScript function to do this?&lt;/p&gt;

&lt;p&gt;NO!! &lt;/p&gt;

&lt;p&gt;Callback functions make things reusable.  Since we as the developers are responsible for defining what that callback function will do, we can reuse the &lt;code&gt;arr.map()&lt;/code&gt; function for a variety of purposes.  Here's how I would implement the idea I just presented.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Zach&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myCustomMapOperation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;itemFromArray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// You can grab characters from a string value just like you can &lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;itemFromArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myCustomMapOperation&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["H", "w", "m", "n", "i", "Z"];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Asynchronous Programming: Callbacks, Promises, and async-await
&lt;/h4&gt;

&lt;p&gt;Yep, I said it.  "Asynchronous" is a word that you're going to learn to love and hate at the same time.&lt;/p&gt;

&lt;p&gt;In programming, not all operations happen near-instantaneous like the code we have been writing does.  For example, what happens when a web app needs to fetch some data from a database and the internet is slow that day?  This operation is going to take a couple of seconds depending on the latency of your internet.&lt;/p&gt;

&lt;p&gt;You might say–well then, let's just wait until it is done before executing any more code?&lt;/p&gt;

&lt;p&gt;Wrong answer, but a good thought.  We cannot just wait for it to happen because in many apps, there are hundreds of these operations happening at once and if we waited for each of them, our webpage would take &lt;strong&gt;several minutes to load&lt;/strong&gt;.  Nobody wants that.&lt;/p&gt;

&lt;p&gt;We will not be diving into any code in this lesson, but there will be a &lt;strong&gt;future lesson solely devoted to covering asynchronous programming&lt;/strong&gt; because it is a large topic and can get rather confusing.&lt;/p&gt;

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

&lt;p&gt;If you've been following along with this lesson series, you might have heard me say "everything in JavaScript is an object".  Until now, I haven't explained myself.&lt;/p&gt;

&lt;p&gt;But since we will be covering a lot of these built-in JavaScript functions and objects in this lesson, you need to have a basic understanding of primitives vs. objects.&lt;/p&gt;

&lt;p&gt;Here is what I mean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember the &lt;code&gt;===&lt;/code&gt; and &lt;code&gt;==&lt;/code&gt; from lesson 3?  Triple equals compares both &lt;em&gt;type&lt;/em&gt; and &lt;em&gt;value&lt;/em&gt;.  Double equals just compares &lt;em&gt;value&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The value of these "strings" are equal, but the type is not (one is an object and one is a string).&lt;/p&gt;

&lt;p&gt;You're probably thinking–"so you're telling me that &lt;code&gt;string1&lt;/code&gt; is not a string???!".&lt;/p&gt;

&lt;p&gt;That's exactly what I'm telling you.  And furthermore, some might argue that &lt;code&gt;string2&lt;/code&gt; is not a string because it has "methods" on it.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This code is valid&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;am I a string?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How on earth can a "string" also have a method like this?  We will not answer this question in a huge amount of detail, but I want to at least address it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a primitive value?
&lt;/h3&gt;

&lt;p&gt;Think of a "primitive" as the &lt;em&gt;simplest&lt;/em&gt; form of something.  If a coding language had a "periodic table of elements", it would be filled with "primitives".&lt;/p&gt;

&lt;p&gt;In JavaScript, there are six primitives.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;number&lt;/li&gt;
&lt;li&gt;bigint&lt;/li&gt;
&lt;li&gt;boolean&lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;li&gt;symbol&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We haven't talked about all of these, and that's okay.&lt;/p&gt;

&lt;p&gt;A "primitive" data type does not have any "methods" attached to it, but behind the scenes, JavaScript &lt;em&gt;wraps&lt;/em&gt; primitive values with their corresponding Object value.  This is why &lt;code&gt;'some string'.toUpperCase()&lt;/code&gt; is valid JavaScript code.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what do I do about this?
&lt;/h3&gt;

&lt;p&gt;I created this section of the lesson series because this was a question that I had when I learned JavaScript.&lt;/p&gt;

&lt;p&gt;I recommend that you &lt;strong&gt;take this as "good to be aware of" information&lt;/strong&gt;, but do not go any further than that yet.  Once you are more experienced, you can go back and learn the underlying details of the JavaScript language.  If you are a naturally curious person like me, I suggest reading the following short resources and then return to the lesson.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_primitives_and_string_objects"&gt;String Primitives vs. String Objects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Primitive"&gt;What are primitives?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's return to the code at the beginning of this section with some comments to wrap up our short discussion on primitives.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// DO NOT define your strings like this&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// DO define your strings like this&lt;/span&gt;
&lt;span class="c1"&gt;// We call this a "string literal" &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="c1"&gt;// Here, we are converting string1 from an Object to a primitive and then comparing&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valueOf&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="c1"&gt;// JavaScript will wrap string2 in a String object prior to executing this method&lt;/span&gt;
&lt;span class="c1"&gt;// You don't need to do anything further than this&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is this "new" keyword?
&lt;/h3&gt;

&lt;p&gt;Another reason I wanted to visit this section is because as we move into topics like JavaScript Dates (next section), you will start to see a JavaScript keyword, &lt;code&gt;new&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Technically, &lt;code&gt;new&lt;/code&gt; is an operator, but we didn't cover it in our lesson about operators.  Here is what the &lt;code&gt;new&lt;/code&gt; operator does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creates a blank JavaScript object&lt;/li&gt;
&lt;li&gt;Links this new object to a "parent" object&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are actually &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new"&gt;some additional steps&lt;/a&gt;, but not relevant to us yet.&lt;/p&gt;

&lt;p&gt;In plain English, the &lt;code&gt;new&lt;/code&gt; operator creates an "instance" of an existing object.  &lt;strong&gt;We will revisit this concept later in the series.&lt;/strong&gt;  For now, whenever you see the &lt;code&gt;new&lt;/code&gt; operator, just think of it like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We have some existing, pre-defined object such as &lt;code&gt;Date&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We want a "copy" of that object that we can store in a variable&lt;/li&gt;
&lt;li&gt;So... We use the &lt;code&gt;Date&lt;/code&gt; as a "template" to create that "copy"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Speaking of dates...&lt;/p&gt;

&lt;h2&gt;
  
  
  Dates
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;Official Documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'm going to let you in on a secret–most developers don't have a great understanding of JavaScript dates.  Don't worry if dates confuse you initially.  I have &lt;a href="https://www.zachgollwitzer.com/posts/2020/js-dates/"&gt;an entire post explaining them&lt;/a&gt; if you are interested in diving much deeper.&lt;/p&gt;

&lt;p&gt;Anyways, here is the quick-start.  To create a new date object (remember, &lt;code&gt;new&lt;/code&gt; just creates a "copy" of the &lt;code&gt;Date&lt;/code&gt; "template"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Thu Jan 14 2021 10:51:27 GMT-0500 (Eastern Standard Time)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value stored within this date object represents &lt;strong&gt;the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can see that value by using the &lt;code&gt;valueOf()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;millisecondsValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;valueOf&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Thu Jan 14 2021 10:53:26 GMT-0500 (Eastern Standard Time)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;millisecondsValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1610639606819&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why January 1st, 1970?  What is UTC? Again, &lt;a href="https://www.zachgollwitzer.com/posts/2020/js-dates/"&gt;read my detailed post&lt;/a&gt; if you're curious.&lt;/p&gt;

&lt;p&gt;If you want to define a specific date, you can pass a variety of arguments into the Date object.  Again, if you want the nitty gritty details, &lt;a href="https://www.zachgollwitzer.com/posts/2020/js-dates/"&gt;read my post on JS Dates.&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// EXAMPLE #1&lt;/span&gt;
&lt;span class="c1"&gt;// Inputs as arguments&lt;/span&gt;
&lt;span class="c1"&gt;// Date(year, month, day, hour, minute, second, millisecond)&lt;/span&gt;
&lt;span class="c1"&gt;// Note: the month is 0-indexed (I have no clue why...)&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// EXAMPLE #2&lt;/span&gt;
&lt;span class="c1"&gt;// Inputs as various strings&lt;/span&gt;
&lt;span class="c1"&gt;// This works with pretty much anything you can think of&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20 2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;January 20 2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan-20-2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20 2020 02:20:10&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// EXAMPLE #3&lt;/span&gt;
&lt;span class="c1"&gt;// Inputs as numbers (milliseconds)&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;102031203&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// EXAMPLE #4&lt;/span&gt;
&lt;span class="c1"&gt;// Inputs as ISO 8601 (we are about to talk about this)&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2020-01-20T00:00Z&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// EXAMPLE #5&lt;/span&gt;
&lt;span class="c1"&gt;// Inputs with timezone specifications&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20 2020 02:20:10 -10:00&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// SPECIAL CASE&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20 2020 02:20:10 -1000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// SPECIAL CASE&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20 2020 02:20:10 (EDT)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// SPECIAL CASE&lt;/span&gt;
&lt;span class="c1"&gt;// EXAMPLE #6&lt;/span&gt;
&lt;span class="c1"&gt;// The current moment, specified in the user's local timezone&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// SPECIAL CASE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some useful Date methods
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;toString()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toISOString()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;getDate()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;getMonth()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;getFullYear()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the common ones.  For more, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;visit the documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is a quick example how you can use these methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Prints the local date and time&lt;/span&gt;
&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Thu Jan 14 2021 10:53:26 GMT-0500 (Eastern Standard Time)&lt;/span&gt;

&lt;span class="c1"&gt;// Prints date in ISO8601 format.  See - https://cdn-images-1.medium.com/max/2000/1*f1Ye0uCRt1ziCG18sl74CQ.png &lt;/span&gt;
&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 2021-01-14T15:53:26.819Z&lt;/span&gt;
&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Returns 14 because I'm writing this on Jan 14, 2021&lt;/span&gt;
&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMonth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Returns 0 because the month method is zero-indexed (i.e. Jan = 0, Feb = 1)&lt;/span&gt;
&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Returns 2021&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think that is enough for now.  You don't need to be an expert in JS dates, but definitely need to have some familiarity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Regular Expressions
&lt;/h2&gt;

&lt;p&gt;A "regular expression" can almost be considered a language on its own (not turing complete of course).  The purpose of a regular expression is to find characters within a string based on a certain pattern that you define.&lt;/p&gt;

&lt;p&gt;This is a loaded topic and confusing one, but you WILL use regular expressions as a developer.  Below is a 10,000 foot summary of regular expressions.  If you want more detail, please read &lt;a href="https://www.zachgollwitzer.com/posts/2019/regexp-bash/"&gt;my detailed post on them&lt;/a&gt;.  At this point in your journey, getting deep into regular expressions is probably not the priority.  &lt;strong&gt;The important thing right now is to know what they are, what they do, and how to read them–not how to write them.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp"&gt;Here is the documentation&lt;/a&gt; for regular expressions.&lt;/p&gt;

&lt;p&gt;The best example that we can use to explain why regular expressions (often abbreviated as "regex" or "regexp") matter is &lt;strong&gt;validation of form data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's say that you have a user register form for your app, and over the last several weeks, you've been getting a lot of invalid email addresses registering for your app.  You of course don't want this.  You want valid emails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpy1bu9ng9cmmn2dq8som.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpy1bu9ng9cmmn2dq8som.JPG" alt="login validation" width="335" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To avoid this, you can validate the user's input with a regex prior to registering them.  Here is how you might do this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emailValidatorRegex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;^.+@.+&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s1"&gt;..+$&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;invalidemail@g&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;emailValidatorRegex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isValid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;^.+@.+\..+$&lt;/code&gt; is considered the regular expression, and all of those symbols represent something very specific.  This is by no means the &lt;em&gt;best&lt;/em&gt; regex to use for validating emails (it actually overlooks a lot of scenarios), but it is a good place for us to start.&lt;/p&gt;

&lt;p&gt;Before we explain this pattern, I want to introduce the absolute basics of regular expressions.&lt;/p&gt;

&lt;p&gt;No matter what language you're working in, regular expressions follow the same structure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identifiers&lt;/li&gt;
&lt;li&gt;Quantifiers&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Identifiers
&lt;/h3&gt;

&lt;p&gt;These help you identify characters within a string.  They can be anything from a single character to a more advanced expression.&lt;/p&gt;

&lt;p&gt;For example, to identify a string that has the letter &lt;code&gt;g&lt;/code&gt; in it, you can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;g&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could also check for an entire word.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;favorite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Regular expressions are case-sensitive, so the following expression won't match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;FavoritE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Identifiers do not have to be letters, numbers, and words.  There are "special" identifiers that can identify &lt;em&gt;patterns&lt;/em&gt;.  Here are a few common examples, but you can find a more exhaustive list in my &lt;a href="https://www.zachgollwitzer.com/posts/2019/regexp-bash/"&gt;detailed post on regular expressions&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[A-Z]&lt;/code&gt; - Match all uppercase letters&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[a-z]&lt;/code&gt; - Match all lowercase letters&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[0-9]&lt;/code&gt; - Match all numbers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[A-Za-z0-9]&lt;/code&gt; - Match all letters and numbers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; - Match any character (wildcard)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\d&lt;/code&gt; - Match all numbers (another way to write &lt;code&gt;[0-9]&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\s&lt;/code&gt; - Match any white space character&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;\w&lt;/code&gt; - Match all letters and numbers (another way to write &lt;code&gt;[A-Za-z0-9]&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;^&lt;/code&gt; - Indicates the start of a line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$&lt;/code&gt; - Indicates the end of a line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;(dog|cat)&lt;/code&gt; - Matches "dog" OR "cat"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's use &lt;code&gt;[A-Za-z]&lt;/code&gt; as an example.  This matches ALL letters (uppercase AND lowercase).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[A-Za-z]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak 239042038124&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code 23094029340923&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait a second... If &lt;code&gt;[A-Za-z]&lt;/code&gt; matches only letters, then why are the expressions above returning &lt;code&gt;true&lt;/code&gt;?  So far, we have been using the &lt;code&gt;test()&lt;/code&gt; method, which will check if your regular expression matches ANY PART of a string.  But what part did it match??  To find out, you can use the &lt;code&gt;exec()&lt;/code&gt; method, which will return an array that tells you &lt;em&gt;what&lt;/em&gt; was matched in your string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[A-Za-z]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak 239042038124&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code 23094029340923&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using the exec() method&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ["m", index: 0, input: "my favorite food is steak 239042038124", groups: undefined]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ["m", index: 0, input: "my favorite thing to do is code 23094029340923", groups: undefined]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the first element of the array is the substring that was matched.  The second element tells you at what index of the string it was matched at.  In this case, we matched the first letter of each string, which has a &lt;code&gt;0&lt;/code&gt; index.  The third element is the original string, and the fourth element shows the groups that were matched (but this is an advanced topic we will not be covering).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So... Why did we only match the first letter of each string?  Doesn't &lt;code&gt;[A-Za-z]&lt;/code&gt; match ALL letters?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Queue quantifiers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quantifiers
&lt;/h3&gt;

&lt;p&gt;Here are the quantifiers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;*&lt;/code&gt; - Matches 0 or more of the preceding character&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt; - Matches 1 or more of the preceding character&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;?&lt;/code&gt; - Matches 0 or 1 of the preceding character&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{1}&lt;/code&gt; - Matches exactly 1 of the preceding character&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{1,}&lt;/code&gt; - Matches 1 or more of the preceding character (identical to +)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{2,6}&lt;/code&gt; - Matches between 2 and 6 of the preceding character&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And this is how we can fix our code from above to match ALL of the letters.  By adding &lt;code&gt;*&lt;/code&gt; at the end, we are saying, "match 1 or more letters".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[A-Za-z]+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak 239042038124&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code 23094029340923&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using the exec() method&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ["my", index: 0, input: "my favorite food is steak 239042038124", groups: undefined]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ["my", index: 0, input: "my favorite thing to do is code 23094029340923", groups: undefined]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll notice that the first element of both arrays equals &lt;code&gt;my&lt;/code&gt;, which is still not what we are trying to match!  The reason–we did not match the spaces between the words!&lt;/p&gt;

&lt;p&gt;All you have to do is add a space in your character group (the brackets).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// WE CHANGED THIS LINE - see the space at the end??
const regex = new RegExp('[A-Za-z ]+');

const string1 = 'my favorite food is steak 239042038124';
const string2 = 'my favorite thing to do is code 23094029340923';

// Using the exec() method
console.log(regex.exec(string1)); // ["my favorite food is steak ", index: 0, input: "my favorite food is steak 239042038124", groups: undefined]
console.log(regex.exec(string2)); // ["my favorite thing to do is code ", index: 0, input: "my favorite thing to do is code 23094029340923", groups: undefined]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, our &lt;code&gt;exec()&lt;/code&gt; method returns all of the words.&lt;/p&gt;

&lt;p&gt;And finally, if we wanted to match the entire string, we could of course just add &lt;code&gt;0-9&lt;/code&gt; into our character group, but I'm going to do it in a slightly inefficient way to demonstrate something.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// WE CHANGED THIS LINE - see the space at the end??&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[A-Za-z ]+[0-9]+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak 239042038124&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite thing to do is code 23094029340923&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using the exec() method&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ["my favorite food is steak 239042038124", index: 0, input: "my favorite food is steak 239042038124", groups: undefined]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// ["my favorite thing to do is code 23094029340923", index: 0, input: "my favorite thing to do is code 23094029340923", groups: undefined]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we want to match any letter or space (identifier: &lt;code&gt;[A-Za-z ]&lt;/code&gt;) 1 or more times (quantifier: &lt;code&gt;+&lt;/code&gt;) and then match 1 or more numbers (&lt;code&gt;[0-9]+&lt;/code&gt;).  If we reversed the strings, our expression would no longer work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[A-Za-z ]+[0-9]+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;239042038124 my favorite food is steak&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;23094029340923 my favorite thing to do is code&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using the exec() method&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// null&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our &lt;code&gt;exec()&lt;/code&gt; function returns &lt;code&gt;null&lt;/code&gt; because our regex pattern no longer matches the strings!&lt;/p&gt;

&lt;h3&gt;
  
  
  Another way to write a regular expression
&lt;/h3&gt;

&lt;p&gt;So far, we have written them like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RegExp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[A-Za-z ]+[0-9]+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also write them like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z &lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From my experience, most developers tend to use the second version.&lt;/p&gt;

&lt;p&gt;At this point, we have covered the bare basics of JavaScript regular expressions and for the sake of your sanity and my own, we will stop here.  You can learn more about regular expressions in the future, but hopefully, this brief overview gets you to a place where you can recognize what they do and how to read them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common String Methods
&lt;/h2&gt;

&lt;p&gt;Remember from our discussion above, a String is considered an "object" in JavaScript, and thus, has built-in "methods" (just another word for "functions").  I do not intend to cover all of the String methods (you can &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#instance_methods"&gt;find them here&lt;/a&gt;) nor do I intend to explain any one of these in extreme detail.  My intention is to show you some of the common methods and the basics of how they work so when it comes time to use them, you will already have some familiarity.&lt;/p&gt;

&lt;p&gt;Here are the string methods that I find myself using most.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;replaceAll()&lt;/li&gt;
&lt;li&gt;toUpperCase()&lt;/li&gt;
&lt;li&gt;substring()&lt;/li&gt;
&lt;li&gt;trim()&lt;/li&gt;
&lt;li&gt;match()&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  replaceAll
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll"&gt;Official Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method comes in handy when you want to replace multiple occurrences of a value in a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My Dog jumped on the bed.  My dog is a bad Dog.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Remember, a string primitive like `myString` is immutable, so we are&lt;/span&gt;
&lt;span class="c1"&gt;// not editing it directly.  We are assigning the result to a new variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dog&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// My Cat jumped on the bed.  My dog is a bad Cat.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice anything wrong here?  We only replaced the uppercase version of &lt;code&gt;Dog&lt;/code&gt;!  This is where regular expressions come in handy.  The &lt;code&gt;replaceAll()&lt;/code&gt; method accepts &lt;em&gt;either&lt;/em&gt; a string OR a regular expression for its first argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My Dog jumped on the bed.  My dog is a bad Dog.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;Dd&lt;/span&gt;&lt;span class="se"&gt;]{1}&lt;/span&gt;&lt;span class="sr"&gt;og/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cat&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// My cat jumped on the bed.  My cat is a bad cat.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We wrote &lt;code&gt;/[Dd]{1}og/g&lt;/code&gt; as our regular expression which will match exactly 1 character that is either &lt;code&gt;D&lt;/code&gt; or &lt;code&gt;d&lt;/code&gt; followed by &lt;code&gt;og&lt;/code&gt;.  The &lt;code&gt;g&lt;/code&gt; character at the end is not something we talked about earlier, but it represents the "global" flag (i.e. match ALL occurrences of this pattern rather than just the first).  For more on regular expression flags, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags_2"&gt;you can read this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As you can see above, we replaced all occurrences of "dog" (uppercase and lowercase) by using a single expression.&lt;/p&gt;

&lt;h3&gt;
  
  
  toUpperCase
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method does exactly what its name suggests.  It capitalizes every letter in a given string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// SOME STRING&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see how this method can be useful in the next method, &lt;code&gt;substring()&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  substring
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring"&gt;Official Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look in the documentation, you'll see the following two methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4eaon6phpehjat5olqtq.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4eaon6phpehjat5olqtq.JPG" alt="substring" width="269" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that thumbs down icon?  That means that the method is "deprecated" (no longer supported).  Deprecated methods will still work in most cases, but may become unsupported by certain browsers over time.&lt;/p&gt;

&lt;p&gt;While I did accidentally use &lt;code&gt;substr()&lt;/code&gt; in a prior lesson during one of our code challenges, you should always use &lt;code&gt;substring()&lt;/code&gt; because it is not deprecated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This method is great when you need to isolate a section of a string&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Index          0123456789 ......&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the programmer had a lot of bugs in his house&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;substr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// programmer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the index values that I placed above the first couple letters in &lt;code&gt;myString&lt;/code&gt;.  The &lt;code&gt;substring()&lt;/code&gt; method takes two arguments–the starting index and ending index.  In this example, we start at index &lt;code&gt;4&lt;/code&gt; and end at index &lt;code&gt;14&lt;/code&gt;.  If you would have skipped the first argument (i.e. &lt;code&gt;myString.substring(4)&lt;/code&gt;), the method would return the entire string &lt;em&gt;starting at&lt;/em&gt; index &lt;code&gt;4&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This method can come in handy in lots of situations, but here's one that I've found myself using it for which utilizes &lt;code&gt;substring()&lt;/code&gt; and &lt;code&gt;toUpperCase()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Index          0123456789 ......&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the programmer had a lot of bugs in his house&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Capitalize the first letter of the sentence&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;substr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// The programmer had a lot of bugs in his house&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;myString[0]&lt;/code&gt; retrieves the first letter of the string.  We then take that value and make it uppercase using &lt;code&gt;toUpperCase()&lt;/code&gt;.  We then use the &lt;code&gt;substring()&lt;/code&gt; method to get the remainder of the string (start at index 1, which is the second letter and end at the final letter, which should have an index equal to the length of the string).  Finally, we "add" or "concatenate" these two strings together.&lt;/p&gt;

&lt;h3&gt;
  
  
  trim
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim"&gt;Official Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method will "trim" the whitespace off the ends of a string.  It may not seem apparent why this is useful, but sometimes, when you grab data from an external API or database, you can't be sure whether the format of that data will be correct.&lt;/p&gt;

&lt;p&gt;For example, let's say you get the following data from an external API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;externalData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How to code      &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; What is Vim?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;  How do loops work in JavaScript?    &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The data itself looks fine, but you've got some extra spaces that don't need to be there.  Here's how you fix it using &lt;code&gt;trim()&lt;/code&gt; and a basic for loop (see last lesson).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;externalData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How to code      &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; What is Vim?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;  How do loops work in JavaScript?    &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;externalData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentTitle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentAuthor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentTitle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;externalData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentAuthor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;externalData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run this code, you'll see that the objects in the array no longer have spaces around them.  It is important to note that &lt;code&gt;trim()&lt;/code&gt; only removes the spaces at the &lt;em&gt;beginning&lt;/em&gt; and &lt;em&gt;end&lt;/em&gt; of the string; not the spaces between the words.  That is why our titles still have those spaces.&lt;/p&gt;

&lt;h3&gt;
  
  
  match
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So... Remember how we talked about those things called "regular expressions" a couple of hundred words ago?  Well, they're back.  Again.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;match()&lt;/code&gt; method is very similar to the &lt;code&gt;exec()&lt;/code&gt; method we talked about with regular expressions.  Let's look at them both for comparison.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z &lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my favorite food is steak 239042038124&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Using the exec() method&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Using the match() method&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
  Both result1 and result2 equal: 

  ["my favorite food is steak 239042038124", index: 0, input: "my favorite food is steak 239042038124", groups: undefined]
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These two methods will return the same exact value as long as you are NOT using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags_2"&gt;global flag&lt;/a&gt; in your regular expression.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;Array Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we are on to arrays!  The same rules apply for this section–I'm not intending to provide an exhaustive list with exhaustive explanations; just giving an overview of some of the most common methods.&lt;/p&gt;

&lt;p&gt;Here are the array methods that I find myself using most.  Please note that most of them require a decent understanding of callback functions, so be sure to re-read the section above if you're still fuzzy on those.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;push() / pop() / shift() / unshift()&lt;/li&gt;
&lt;li&gt;slice()&lt;/li&gt;
&lt;li&gt;splice()&lt;/li&gt;
&lt;li&gt;findIndex() / indexOf()&lt;/li&gt;
&lt;li&gt;map()&lt;/li&gt;
&lt;li&gt;forEach()&lt;/li&gt;
&lt;li&gt;includes()&lt;/li&gt;
&lt;li&gt;filter()&lt;/li&gt;
&lt;li&gt;reduce()&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Remember, these are not to memorize!&lt;/strong&gt;.  You can always look them up.  I'm showing them to you so that you are &lt;em&gt;aware&lt;/em&gt; of them and can identify when they might be useful.&lt;/p&gt;

&lt;p&gt;My goal here is not to detail every last thing you can do with each method.  The documentation already does that.  My goal is to point out &lt;em&gt;why&lt;/em&gt; you might want to use these methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  push, pop, shift, unshift
&lt;/h3&gt;

&lt;p&gt;Official docs - &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push"&gt;push&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop"&gt;pop&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift"&gt;shift&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift"&gt;unshift&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are related.  They let you add/remove elements from an array.  From my experience, &lt;code&gt;push()&lt;/code&gt; is the most common method that you will use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Add element to end of array&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// New array: [1, 2, 3, 4]&lt;/span&gt;

&lt;span class="c1"&gt;// Add element to beginning of array&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// New array: [0, 1, 2, 3, 4];&lt;/span&gt;

&lt;span class="c1"&gt;// Remove last element of array&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// New array: [0, 1, 2, 3]&lt;/span&gt;

&lt;span class="c1"&gt;// Remove first element of array&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// New array: [1, 2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  slice
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;arr.slice()&lt;/code&gt; method comes in handy when you need to make a copy of an array.  To a beginner, this may seem useless, but when you start dealing with immutable state in a front-end framework like React, this method will be invaluable to you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;please&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;subscribe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;to&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;YouTube channel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fullCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// ['please', 'subscribe', 'to', 'my', 'YouTube channel']&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;partialCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ['please', 'subscribe']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  splice (not to be confused with slice)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to add an element somewhere other than the beginning (&lt;code&gt;unshift()&lt;/code&gt;) or end (&lt;code&gt;push()&lt;/code&gt;) of an array, &lt;code&gt;splice()&lt;/code&gt; is your method.  Here is a common way to use it.  See the docs for more use cases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Index                       0  1  2    3     4  5 &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;somethingDoesntBelong&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;oops&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Start at index 3, delete 1 item, and replace with the number 4&lt;/span&gt;
&lt;span class="nx"&gt;somethingDoesntBelong&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;somethingDoesntBelong&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, 5, 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  findIndex / indexOf
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;findIndex&lt;/code&gt; method accepts a callback function as an argument and will find the first element in an array that matches the conditions set in your callback function.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;indexOf&lt;/code&gt; method simply searches for the first occurrence of a value in an array and is a much simpler method to use.&lt;/p&gt;

&lt;p&gt;Let's start easy with the &lt;code&gt;indexOf&lt;/code&gt; method.  This just locates a value in an array, and if it doesn't find it, returns &lt;code&gt;-1&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blueIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;purpleIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// -1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if you have a more complex array like this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;moreComplexArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How do we find the person with the last name of "Doe"?  You might think about trying something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Using array from above&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;valueToFind&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// DOESNT WORK!!! Returns -1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resultIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;moreComplexArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;valueToFind&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This doesn't work because checking the equality of an object is a bit more complex than just passing it in as a value.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;findIndex&lt;/code&gt;, we can locate this element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;moreComplexArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;incorrectIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;moreComplexArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// THIS DOES WORK&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;correctIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;moreComplexArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findIndex&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;arrItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arrItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;incorrectIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// -1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;correctIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;findIndex()&lt;/code&gt; method provides a lot more flexibility!&lt;/p&gt;

&lt;h3&gt;
  
  
  map
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of all these built-in array methods, this one is probably my most used.  Here is a very practical example.  Let's say you have retrieved an array of blog posts from your database and the &lt;code&gt;category&lt;/code&gt; property is not filled out.  For all these blog posts, you want them to be categorized in the "Learn to Code" category.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blogPostsFromDatabase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How to use the map() function&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uncategorized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;What is JavaScript?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uncategorized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Why are you crazy enough to learn to code?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uncategorized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ourCustomCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blogPost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;blogPost&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Learn to Code&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;blogPost&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resultingArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;blogPostsFromDatabase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ourCustomCallback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*

Here is our resultingArray

[
  {
    title: 'How to use the map() function',
    category: 'Learn to Code'
  },
  {
    title: 'What is JavaScript?',
    category: 'Learn to Code'
  },
  {
    title: 'Why are you crazy enough to learn to code?',
    category: 'Learn to Code'
  },
];


*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The map method can be used in a TON of different situations.  If you ever have an array where each element of the array needs to be modified in a similar way, the map method will come in handy.&lt;/p&gt;

&lt;h3&gt;
  
  
  forEach
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far, I have only shown you how to write a basic for loop.  Here is what we have looked at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Do something with each element of array&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there is a simpler way to write this same for loop–the &lt;code&gt;forEach()&lt;/code&gt; Array method.&lt;/p&gt;

&lt;p&gt;Please &lt;a href="https://stackoverflow.com/a/43032526/7437737"&gt;read this&lt;/a&gt; for a comparison of the basic &lt;code&gt;for&lt;/code&gt; loop and the &lt;code&gt;forEach&lt;/code&gt; loop.  The short answer–each way has its advantages, and in &lt;em&gt;most&lt;/em&gt; cases, which one you choose does not matter.&lt;/p&gt;

&lt;p&gt;Here is the basic way to use this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// We aren't using the `indexOfItem`, but I wanted to put it here to show that it is available to you&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myCallbackFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arrItem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;indexOfItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;arrItem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myCallbackFunc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a cleaner (but less beginner-friendly) way to write this.  Here, we are using an arrow function as the callback rather than defining it separately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arrItem&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;arrItem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  includes
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you ever need to figure out whether a value exists in an array, use this method.  Please note that you &lt;em&gt;cannot&lt;/em&gt; use this to find complex data types like objects or other arrays.&lt;/p&gt;

&lt;p&gt;Let's say that you have the following array, and you want to figure out whether the color &lt;code&gt;orange&lt;/code&gt; exists in it.  You can clearly see that it does, but you won't always have this clarity while writing code.  Maybe this array came from a database and you don't know what to expect!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is one way that we could figure it out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;orangeExists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myColors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;orangeExists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orangeExists&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is a simpler way to do it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;orangeExists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;myColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;orangeExists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orangeExists&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But by using &lt;code&gt;includes()&lt;/code&gt;, we can do it even simpler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;orangeExists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orangeExists&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Furthermore, you could have even used a different method altogether to achieve this.  See below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;orangeExists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;orangeExists&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We know that if &lt;code&gt;indexOf&lt;/code&gt; does NOT find the element in the array, it returns a value of &lt;code&gt;-1&lt;/code&gt;.  I know this because I read the documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdddkmpsu5phdqd8a6mws.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdddkmpsu5phdqd8a6mws.JPG" alt="index of method" width="556" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can use this logic to determine if a value exists in an array; similar to the &lt;code&gt;includes()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Hopefully, you are starting to see how much code these built-in methods can save you from writing if you know when to use them!&lt;/p&gt;

&lt;h3&gt;
  
  
  filter
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Behind &lt;code&gt;map()&lt;/code&gt;, this might be my second most utilized built-in array method.&lt;/p&gt;

&lt;p&gt;Unlike some of these other methods, the &lt;code&gt;filter()&lt;/code&gt; method has a very obvious use-case that most people can resonate with even if they don't write a lot of code.&lt;/p&gt;

&lt;p&gt;Let's say we are building the "My Orders" page for Amazon.  On this page, you can view all of your past orders, but you can also filter by various conditions.  You can display orders for a certain time frame, your open orders, your digital-only orders, and your canceled orders.&lt;/p&gt;

&lt;p&gt;When Amazon loads the data into this page, it likely comes in the form of an array (this is a fictional representation):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allOrders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tea pot&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isDigital&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isCancelled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Blue Gildan Mens Hoodie&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isDigital&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isCancelled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Code Complete Kindle Book&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isDigital&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isCancelled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Atomic Habits Kindle Book&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isDigital&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isCancelled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the user clicks the filter to select only the Digital orders, how might we write the code to do that?  Using the &lt;code&gt;filter()&lt;/code&gt; method of course!  We can also get an array with combined filters!&lt;/p&gt;

&lt;p&gt;Here's how it works–if the return value of our callback function is true for a specific array item, then this array item will be included in the resultant array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;digitalOrders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;allOrders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDigital&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;digitalCancelledOrders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;allOrders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDigital&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isCancelled&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;physicalOrders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;allOrders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;orderItem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDigital&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will use this method a lot, so learn it well!&lt;/p&gt;

&lt;h3&gt;
  
  
  reduce
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I saved the hardest for last because while it can come in handy, you don't &lt;em&gt;need&lt;/em&gt; it.  Take a look at the example, but don't stress over learning this–we have more important things to learn over the next few lessons.&lt;/p&gt;

&lt;p&gt;You probably recognize this by now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 99&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;reduce()&lt;/code&gt; method is just a shorter way of writing this code.&lt;/p&gt;

&lt;p&gt;Here is the same code from above re-written using the &lt;code&gt;reduce()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reducerCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currArrItem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currArrIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;currArrItem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 0 represents the "initial value"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducerCallback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 99&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We start our &lt;code&gt;sum&lt;/code&gt; value at &lt;code&gt;0&lt;/code&gt; by passing it in as the second argument (just like we did in the code prior to this).  The &lt;code&gt;reducerCallback&lt;/code&gt; will loop through each value in the array and increment the value of &lt;code&gt;sum&lt;/code&gt; by each item in the array.  This callback function will then return the "accumulated" &lt;code&gt;sum&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  But what if a method doesn't exist for what I'm trying to do?
&lt;/h3&gt;

&lt;p&gt;Glad you asked.  In some cases, you might want to perform some operation that cannot be done using the built-in JavaScript methods.&lt;/p&gt;

&lt;p&gt;In that case, you have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write a bunch of JavaScript code to solve the problem&lt;/li&gt;
&lt;li&gt;Use a JavaScript "library"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you tried to compare the equality of objects by writing "Vanilla" (plain) JavaScript code, &lt;a href="https://stackoverflow.com/a/1144249/7437737"&gt;here's what you would need to write&lt;/a&gt;.  I don't recommend it.&lt;/p&gt;

&lt;p&gt;The better solution is to use a code library like Lodash.  We will talk a lot more about code libraries and how to use them later, but for now, just take a glance at the code I've written below (utilizing the Lodash library).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick tip&lt;/strong&gt;: The Lodash library provides functions for various data types (similar to the JavaScript built-in functions) and we often refer to it as "functional programming".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Don't worry, we have not covered this yet and I don't expect you to know it&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lodashLib&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// As a side-note, the "convention" that a lot of programmers use to import &lt;/span&gt;
&lt;span class="c1"&gt;// this library is to use an underscore as the name of it.  You will see this a lot.&lt;/span&gt;
&lt;span class="c1"&gt;// const _ = require('lodash');&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;objA&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false (you can't compare equality of JS objects)&lt;/span&gt;

&lt;span class="c1"&gt;// If we tried to implement this ourselves, it would take 100s of lines of code&lt;/span&gt;
&lt;span class="nx"&gt;lodashLib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;objA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objB&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In future lessons, we will walk through how to use a library like this.&lt;/p&gt;

&lt;h2&gt;
  
  
  The JavaScript Math Library
&lt;/h2&gt;

&lt;p&gt;Even if you are not building Finance web applications, you are going to need to know a couple common functions from the JavaScript Math library.&lt;/p&gt;

&lt;p&gt;Now I want to touch on a minor point (at least in our journey) before we get started.  Take a look at the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;negNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;posNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;negNum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dates and the Math library are unrelated, but do you notice anything weird about the code above?  I do.  In the first code snippet, we are creating a Date using &lt;code&gt;new Date()&lt;/code&gt; while in the second snippet, we are using the Math library as &lt;code&gt;Math.abs()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Don't we need to do this???&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;math&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NO, this is an incorrect way to use the Math library and if you try to run that code, you're going to get the following error message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught TypeError: Math is not a constructor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is that word, "constructor"?? &lt;/p&gt;

&lt;p&gt;Well, it has to do with &lt;em&gt;constructing&lt;/em&gt; an Object in JavaScript and has its roots in something called "Object-Oriented Programming" (OOP).  Later in this series, we will discuss this along with the concept of "classes", "static methods", and "instance methods".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Math.abs()&lt;/code&gt; is a &lt;em&gt;static method&lt;/em&gt; while &lt;code&gt;myDate.getFullYear()&lt;/code&gt; is considered an &lt;em&gt;instance method&lt;/em&gt;.  This is not necessary to know right now, but I wanted to point it out so that when you see it in the future, it is not a complete surprise.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some common uses of the Math library
&lt;/h3&gt;

&lt;p&gt;Even for beginners, the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math"&gt;documentation for the Math library&lt;/a&gt; is not that difficult to read.&lt;/p&gt;

&lt;p&gt;Here are some common ways (not exhaustive) to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Math has some built-in "constants" you can use&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt; &lt;span class="c1"&gt;// 3.141592653589793&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;E&lt;/span&gt; &lt;span class="c1"&gt;// 2.718281828459045&lt;/span&gt;

&lt;span class="c1"&gt;// And some static methods&lt;/span&gt;
&lt;span class="c1"&gt;// Takes absolute value of number&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 60&lt;/span&gt;

&lt;span class="c1"&gt;// Rounds up to nearest integer&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;

&lt;span class="c1"&gt;// Rounds down to the nearest integer&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;

&lt;span class="c1"&gt;// Rounds to nearest integer&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;

&lt;span class="c1"&gt;// Returns smallest/largest number&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;

&lt;span class="c1"&gt;// Returns a random number between 0 and 1&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we move on from this, I want to focus on that &lt;code&gt;Math.random()&lt;/code&gt; method a little bit longer because it will come in handy if you know how to use it.&lt;/p&gt;

&lt;p&gt;Since it returns a random value between 0 and 1, we can use this fact along with some basic logic to get a random index in an array.  We have used this in previous lessons of this series but I have not yet explained how it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Gives us a random number between 0 and 1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// By multiplying by 100, we move the decimal over 2 spaces, and now, we have&lt;/span&gt;
&lt;span class="c1"&gt;// a number between 0 and 100 (but it is still a decimal)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;largerNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// By rounding down, we now have a random, whole number from 0-99&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wholeNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;largerNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Now let's see how this can be useful&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;just&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;an&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lengthOfArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;

&lt;span class="c1"&gt;// Let's combine everything together&lt;/span&gt;
&lt;span class="c1"&gt;// This gives us a random, whole number from 0 - 3, which is the same&lt;/span&gt;
&lt;span class="c1"&gt;// index values we need to access values of our array&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomIndexForArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;lengthOfArr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomArrValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;randomIndexForArray&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may not use this trick in many of your applications, but it sure is useful for unit testing!&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Error types
&lt;/h2&gt;

&lt;p&gt;I know, the rest of this lesson looks rather boring, but if you've made it this far, please stick around because understanding error types, NaN, null, and undefined values are super important!&lt;/p&gt;

&lt;p&gt;A JavaScript error happens when you try to execute JavaScript code that is either invalid or is incapable of handling the values you have given to it.&lt;/p&gt;

&lt;p&gt;In JavaScript, there are several different &lt;em&gt;types&lt;/em&gt; of errors, but they all "inherit" (this is an object-oriented programming term) from the &lt;code&gt;Error&lt;/code&gt; object, which &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error"&gt;you can see the documentation for here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While there are more than just three types, these three are the most common ones that you will see and need a high-level understanding of.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ReferenceError&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;&lt;code&gt;SyntaxError&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TypeError&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript ReferenceError
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you try to "reference", or "use" a value that doesn't exist, you'll get this error.  Here's the simplest example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anotherVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript tries to find a "reference" to &lt;code&gt;anotherVariable&lt;/code&gt; in memory, but since we never declared it, it simply doesn't exist!&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript SyntaxError
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we talk about "syntax", we are talking about &lt;em&gt;how&lt;/em&gt; we write our code.  If you write invalid JavaScript code, the compiler won't know what to do and will throw a &lt;code&gt;SyntaxError&lt;/code&gt;.  This one is pretty easy to explain–just write some invalid JavaScript code!  See if you can figure out what is wrong below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;another value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to run this code, you're going to get a &lt;code&gt;SyntaxError&lt;/code&gt; that says &lt;code&gt;Unexpected token ';'&lt;/code&gt;.  That is because instead of &lt;code&gt;;&lt;/code&gt;, you need &lt;code&gt;,&lt;/code&gt; in your objects.  Here is the correct way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;another value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  JavaScript TypeError
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError"&gt;Official docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is probably the hardest of the three to understand.  It occurs when you try to perform an operation that cannot be done on a specific type of data.  If you try to pass an incompatible argument into a function, attempt to modify an immutable value, or just use a value inappropriately, you will get this error.&lt;/p&gt;

&lt;p&gt;It is confusing because there are many cases that &lt;em&gt;seem&lt;/em&gt; like they would throw a &lt;code&gt;TypeError&lt;/code&gt;, but don't.  Consider this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Does not throw an error&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myObj1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;myObj2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "[object Object][object Object]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can't add two objects right?? No, you can't, but it won't throw an error at you if you try.  It will just combine the two objects together in a string.  Logically speaking, this seems like a &lt;code&gt;TypeError&lt;/code&gt; to me.  But here are a few examples that actually do throw this error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;myNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// TypeError: num.toUpperCase is not a function&lt;/span&gt;
&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// TypeError: myObject.prop1 is not a function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the first case, we are trying to use a String method on a number.  In the second case, we are trying to invoke a function when we are really dealing with a String.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is "Error Handling"
&lt;/h3&gt;

&lt;p&gt;The last thing that I want to cover with errors is something very important, but lost on a lot of beginners (including myself years ago).&lt;/p&gt;

&lt;p&gt;What is the point of "handling" errors, and what does that even mean?&lt;/p&gt;

&lt;p&gt;Well, let me paint a picture for you.  Let's say that you built an application similar to Instagram and one of your users loses internet connectivity while posting a picture.  Clearly, the code that allows the user to post that picture is not going to work because the user doesn't have internet access.&lt;/p&gt;

&lt;p&gt;If we handle the error in our code, we can print something on the screen that says, "You are not connected to the internet.  Please connect and try again".&lt;/p&gt;

&lt;p&gt;If we DO NOT handle the error in our code, our app is going to crash and the user is going to have no idea what happened.&lt;/p&gt;

&lt;p&gt;So the next question is... What errors are we trying to handle? &lt;/p&gt;

&lt;p&gt;And this is where it is difficult for beginners to understand error handling.  In most cases, the errors that we want to handle are ones caused by &lt;em&gt;external&lt;/em&gt; code that we have no control over.  We will cover this in-depth when we get there later in the series, but for now, I'll just show you &lt;em&gt;how&lt;/em&gt; to handle errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// If the code in the try {} block throws an error, &lt;/span&gt;
    &lt;span class="c1"&gt;// we will reach this code block and `err` will represent the Error object&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, the code above is useless and we would never write something like this, but it demonstrates the try/catch syntax that we can use for error handling in JavaScript.&lt;/p&gt;

&lt;p&gt;Since we put &lt;code&gt;num.toUpperCase()&lt;/code&gt; (which throws a &lt;code&gt;TypeError&lt;/code&gt;) in the "try" block, our code runs just fine without being interrupted.  We could even print some details about this error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nx"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// num.toUpperCase is not a function&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I mentioned, we will be revisiting error handling throughout this series, so consider this your brief introduction.&lt;/p&gt;

&lt;h2&gt;
  
  
  NaN, null, undefined in JavaScript
&lt;/h2&gt;

&lt;p&gt;I'm going to keep this final section short and sweet.  There are three "data types" that we have not spent much time on, and those are &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, and &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  NaN - "Not a Number"
&lt;/h3&gt;

&lt;p&gt;You will rarely see this or use this, but you should know what it is.&lt;/p&gt;

&lt;p&gt;From &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN"&gt;the documentation&lt;/a&gt;, here are the most common scenarios that will return &lt;code&gt;NaN&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 1. Trying to coerce a string to a number&lt;/span&gt;
&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// NaN&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Performing an impossible math operation&lt;/span&gt;
&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// NaN&lt;/span&gt;

&lt;span class="c1"&gt;// 3. Operand of an argument is NaN&lt;/span&gt;
&lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 4. Trying to use an arithmetic operator (other than + ) on a string&lt;/span&gt;
&lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I said, you won't see or use this much.&lt;/p&gt;

&lt;h3&gt;
  
  
  null
&lt;/h3&gt;

&lt;p&gt;Unlike NaN, you'll encounter &lt;code&gt;null&lt;/code&gt; values all the time!  A &lt;code&gt;null&lt;/code&gt; value is a JavaScript primitive value (remember from earlier in this post?) and represents the &lt;strong&gt;intentional&lt;/strong&gt; absence of a value.  In other words, you can think of it as a "placeholder" value that must be set by the developer.&lt;/p&gt;

&lt;p&gt;When using &lt;code&gt;null&lt;/code&gt; in an operation, it behaves as a "falsey" value.  See below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this line will not print&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this line will print&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null"&gt;Here is the official documentation&lt;/a&gt; for &lt;code&gt;null&lt;/code&gt; values.&lt;/p&gt;

&lt;h3&gt;
  
  
  undefined
&lt;/h3&gt;

&lt;p&gt;Very similar to &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt; is a primitive value that represents the absence of a value.&lt;/p&gt;

&lt;p&gt;You will get an &lt;code&gt;undefined&lt;/code&gt; value when you try to use a variable that exists, but is not defined yet (and has not been assigned a &lt;code&gt;null&lt;/code&gt; value).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;

&lt;span class="nx"&gt;myObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// TypeError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we didn't &lt;strong&gt;intentionally&lt;/strong&gt; initialize &lt;code&gt;myString&lt;/code&gt; as a &lt;code&gt;null&lt;/code&gt; value, it carries an &lt;code&gt;undefined&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;myObj&lt;/code&gt; example is a bit trickier.  You might infer that because &lt;code&gt;myObj&lt;/code&gt; does not yet have a &lt;code&gt;someFunction&lt;/code&gt; property, it would throw an error.  Instead, all object properties that have not been assigned carry a value of &lt;code&gt;undefined&lt;/code&gt;.  In the example, when we try to invoke this function, we get a &lt;code&gt;TypeError&lt;/code&gt; because you cannot "invoke" and &lt;code&gt;undefined&lt;/code&gt; value.&lt;/p&gt;

&lt;p&gt;Like &lt;code&gt;null&lt;/code&gt;, the &lt;code&gt;undefined&lt;/code&gt; primitive is treated as a "falsey" value when used in a conditional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this line will not print&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this line will print&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Congrats, you made it
&lt;/h2&gt;

&lt;p&gt;If you actually read this entire post, get on Twitter and let me know what you thought! My handle is &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, congrats on finishing this.  I know this stuff is confusing, but with the dedication you have to finish such a long post, I know you will be successful as a software engineer!&lt;/p&gt;

&lt;p&gt;But again, if you just read my posts, you won't learn to code.  You have to practice.  So get on with those challenges!&lt;/p&gt;

&lt;h2&gt;
  
  
  10 JavaScript Challenges
&lt;/h2&gt;

&lt;p&gt;I have chosen 15 challenges for this lesson that will require you to apply the basics of the topics we covered here combined with the knowledge you acquired through prior lessons.&lt;/p&gt;

&lt;p&gt;To get the most out of these challenges, I recommend watching my YouTube video where I solve all of them with you.  I walk you through my thought process and hopefully fill in some gaps from these lessons.&lt;/p&gt;

&lt;p&gt;Here are the challenges and solutions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Solutions - &lt;a href="https://www.youtube.com/watch?v=ijbcs0ESqoM"&gt;YouTube video&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Challenge Collection - &lt;a href="https://www.codewars.com/collections/lesson-6-challenges-number-fullstackroadmap"&gt;Lesson 6 Collection on Codewars&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Lesson 5 - JavaScript Functions, Loops, and Conditionals #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Mon, 11 Jan 2021 16:18:17 +0000</pubDate>
      <link>https://dev.to/zachgoll/lesson-5-javascript-functions-loops-and-conditionals-fullstackroadmap-ej0</link>
      <guid>https://dev.to/zachgoll/lesson-5-javascript-functions-loops-and-conditionals-fullstackroadmap-ej0</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=4LjtotM77Pg&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq&amp;amp;index=10"&gt;See this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is part of my fullstack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first fullstack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please tag me on Twitter &lt;a href="https://twitter.com/zg_dev"&gt;@zg_dev&lt;/a&gt; and share this series with &lt;a href="https://twitter.com/search?q=%23100DaysOfCode&amp;amp;src=typed_query"&gt;#100DaysOfCode&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back.  This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/zg_dev"&gt;My Twitter Profile&lt;/a&gt; - Where you can stay updated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;In the previous two lessons of this series, we covered JavaScript variables and operators in a good amount of detail.&lt;/p&gt;

&lt;p&gt;I believe that if you've been following along and partaking in the practice exercises at the end of each lesson, you should be in a place where we can start moving a bit faster.&lt;/p&gt;

&lt;p&gt;In today's lesson, we will be doing just that.  We will be covering conditionals, loops, and functions in JavaScript rather quickly, and then &lt;strong&gt;supplement that knowledge with a ton of practice.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The lesson itself is necessary, but a lot of the nuances to the JavaScript language will be realized within the practice problems that I will be solving with you at the end of the lesson.  &lt;strong&gt;My goal is to get through 25 practice problems&lt;/strong&gt;, which is going to result in a &lt;strong&gt;REALLY LONG video&lt;/strong&gt;, but I believe that is the cost of learning to code.&lt;/p&gt;

&lt;p&gt;So let's get into it!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are conditionals in JavaScript?
&lt;/h2&gt;

&lt;p&gt;JavaScript conditionals are simpler than I'm making them sound.  Here's a basic JavaScript conditional:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;another string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the strings are equal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// this will be skipped&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the strings are not equal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// this is what will be printed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you completed the previous lesson, you know that these strings are not equal, and therefore, our "code path" will result in the "else" statement and &lt;code&gt;the strings are not equal&lt;/code&gt; will be printed to the console.&lt;/p&gt;

&lt;p&gt;To better understand this, here is the basic structure of a "conditional".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// do something here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// do something here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the previous lesson, we talked about JavaScript expressions, but we only looked at them in the context of variables.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we have to look at what is right of the &lt;code&gt;=&lt;/code&gt; and by doing that, we can determine that &lt;code&gt;(20 === 20) &amp;amp;&amp;amp; ('orange' === 'orange')&lt;/code&gt; is the expression that we are evaluating.  This expression equals &lt;code&gt;true&lt;/code&gt;, and therefore, the &lt;code&gt;myResult&lt;/code&gt; variable is assigned a value of &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When we look at conditionals, our expressions will be placed between parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;put&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;expression&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// write some code here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conditionals can be written in several different ways
&lt;/h3&gt;

&lt;p&gt;Below are some examples of valid conditional statements in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jsExpression&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="c1"&gt;// Only using an if statement (no "else" statement required here)&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jsExpression&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this expression is true&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// An if-else statement&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jsExpression&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this expression is true&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this expression is false&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Adding another "code path" with "else if"&lt;/span&gt;
&lt;span class="c1"&gt;// Hint: you can use as many "else if" statements as you want&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jsExpression&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the expression is true&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the expression is false and the firstNumber is greater than 0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;expression false, and firstNumber 0 or less&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Works the same, just formatted differently&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jsExpression&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;just a different formatting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What about "Switch Statements"?
&lt;/h3&gt;

&lt;p&gt;Now listen up.  If you're using lots of switch statements across your code, you're probably doing something inefficiently.  But... There are some really good use cases for a switch statement and although I can't give you a definitive list of scenarios where you'll need to use this, I can explain why we have it in the first place.&lt;/p&gt;

&lt;p&gt;Consider this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Index           0         1        2         3        4&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Gets a random number between 0 and 4 and stores in a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
  Remember, to get a value from an array, we use bracket notation
  For example, to get 'green', we use `colors[1]`

  Since randomIndex will be a random number between 0-4, we can 
  pass this in as our index to retrieve a random color from the array
*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;randomIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Conditionals&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no color found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The conditional statement we have written at the bottom of the code works fine.  You can use this with no problems, but most developers don't like the look of it.  Here's a cleaner way to write the same thing using a switch/case statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Index           0         1        2         3        4&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Gets a random number between 0 and 4 and stores in a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
  Remember, to get a value from an array, we use bracket notation
  For example, to get 'green', we use `colors[1]`

  Since randomIndex will be a random number between 0-4, we can 
  pass this in as our index to retrieve a random color from the array
*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;randomIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Switch / Case statement&lt;/span&gt;
&lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomColor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is yellow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is purple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the color is blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no color found&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To some, the switch statement looks better than a bunch of if-else statements.  Let me explain what's going on here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variableToEvaluate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value to match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variableToEvaluate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value to match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;// do something here&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// This ensures that if a match is found, no further code is run&lt;/span&gt;
  &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;// If nothing matches above, this code is run&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A switch statement works the same as an if-else statement.  It looks at the value of &lt;code&gt;variableToEvaluate&lt;/code&gt;, and then runs down the list of cases until it finds a "case" where the value matches the variable in question.  If no "case" matches, then we reach the code stored in the &lt;code&gt;default&lt;/code&gt; case.&lt;/p&gt;

&lt;p&gt;Think of it like this–the &lt;code&gt;case&lt;/code&gt; is similar to &lt;code&gt;else if&lt;/code&gt; while the &lt;code&gt;default&lt;/code&gt; is similar to &lt;code&gt;else&lt;/code&gt; in our first example above.&lt;/p&gt;

&lt;p&gt;Like I said, if the switch statement feels a bit uncomfortable right now, there is no need for you to use it.  You can always use the good 'ole "if-else" conditional to filter through a list of potential values.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are loops in JavaScript?
&lt;/h2&gt;

&lt;p&gt;I can tell you &lt;em&gt;what&lt;/em&gt; a loop is, but my goal in this series is to also share with you &lt;em&gt;why&lt;/em&gt; we do things.  As a beginner programmer, understanding why we need loops is not going to be apparent.  Sure, you might find yourself writing loops to solve some algorithm coding challenge, but in the real world of web development, there is one use case for loops that I believe trumps all.&lt;/p&gt;

&lt;p&gt;That use case is &lt;strong&gt;looping over database resources&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the "real world", we deal with a lot of repetitive things with similar characteristics.  Remember how we talked about arrays earlier?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above array is simple, but in a prior lesson, we talked about how you can put more than just string values in an array.  You might have an array that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;What is JavaScript?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach Gollwitzer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dec 20, 2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some post content here&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How do Arrays work?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach Gollwitzer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 1, 2021&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some post content here&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How long does it take to learn coding?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach Gollwitzer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20, 2021&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some post content here&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you notice in the code above?  Here are a few things I'm noticing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, the format of the array above is much different than what we've seen before.  We've looked at a lot of arrays written on a single line, but when coding, you'll often have to write code that breaks on several lines.  While indentation is not necessary (if you are writing Python code it would be, but not JavaScript), it helps with readability.  We will talk later in the series about auto-formatters such as &lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; to help us with this. 👍&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, I'm noticing that each object stored in our &lt;code&gt;blogPosts&lt;/code&gt; array has a very similar structure.  Each object has a &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;author&lt;/code&gt;, &lt;code&gt;publishDate&lt;/code&gt;, and &lt;code&gt;content&lt;/code&gt; property.  Hmmm... We might be able to take advantage of this in a couple minutes...&lt;/p&gt;

&lt;p&gt;When I said "resources" earlier, I'm talking about a group of similar-looking data that is generally stored in a database.  A blog post would be considered an individual "resource".&lt;/p&gt;

&lt;p&gt;So you might ask–why would we want to loop over a list of blog posts?&lt;/p&gt;

&lt;h3&gt;
  
  
  A good idea to remember - don't hardcode things
&lt;/h3&gt;

&lt;p&gt;Let's say you are coding a blog (like we will do in this fullstack series).  How would you display your blog post titles on the home page using the array we just looked at above?&lt;/p&gt;

&lt;p&gt;Here's an idea:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great!  All we need is a little HTML and JavaScript and we have ourselves a list of blog posts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what happens when we add another post?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We could just add another line of code right?  Maybe &lt;code&gt;blogPosts[3].title&lt;/code&gt;?&lt;/p&gt;

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

&lt;p&gt;This is where loops come in.  Instead of hard coding a new line of code for each additional blog post that we add, we want to be able to have our code automatically detect a new blog post and display it.&lt;/p&gt;

&lt;p&gt;Here's how I would display my blog posts instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;What is JavaScript?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach Gollwitzer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dec 20, 2020&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some post content here&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How do Arrays work?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach Gollwitzer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 1, 2021&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some post content here&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;How long does it take to learn coding?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach Gollwitzer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jan 20, 2021&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some post content here&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;// ---------------------&lt;/span&gt;
&lt;span class="c1"&gt;//   This is our loop&lt;/span&gt;
&lt;span class="c1"&gt;// ---------------------&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postTitle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postAuthor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;publishDate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Here, we would use these variables to do something with each post&lt;/span&gt;
  &lt;span class="c1"&gt;// I'll just print the values&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postTitle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postAuthor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postDate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;postContent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No matter how many posts we add to our &lt;code&gt;blogPosts&lt;/code&gt; array, our code is ready to display them!&lt;/p&gt;

&lt;h3&gt;
  
  
  The structure of a JavaScript loop
&lt;/h3&gt;

&lt;p&gt;You will learn later in your programming journey that there are several valid ways to write a loop in JavaScript, but there is one way that most programmers would consider the "standard" way of writing a loop.  You saw it in the code above, but here it is again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your code goes here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know, this looks intimidating.  Let's walk through each part.&lt;/p&gt;

&lt;p&gt;Just like we start a conditional statement with the &lt;code&gt;if&lt;/code&gt; keyword, we start our loops with the &lt;code&gt;for&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The code below is not valid, but gives you a visual&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within the parentheses, we need to add the following things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A loop variable&lt;/li&gt;
&lt;li&gt;A stop condition&lt;/li&gt;
&lt;li&gt;A loop behavior&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this case, we used a loop variable of &lt;code&gt;i&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are a couple things to point out.  First, notice how we have a &lt;code&gt;;&lt;/code&gt; at the end of the statement.  This indicates that our statement is complete and is required.&lt;/p&gt;

&lt;p&gt;Also, notice that we are using &lt;code&gt;let&lt;/code&gt; instead of &lt;code&gt;const&lt;/code&gt;.  This is intentional.  The value of &lt;code&gt;i&lt;/code&gt; will be changing on each iteration of our loop, and therefore, we need to "re-assign" it and use the &lt;code&gt;let&lt;/code&gt; keyword to declare it.&lt;/p&gt;

&lt;p&gt;Next, notice that we named the variable &lt;code&gt;i&lt;/code&gt;.  This is merely a convention, and is not required.  We can call this variable whatever we would like.  The following loop would be perfectly valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Your loop variable doesn't have to be called `i`, but this is a conventional way to do it&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;anyName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;anyName&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;anyName&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Your code goes here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, notice that we initialized this variable with a value of &lt;code&gt;0&lt;/code&gt;.  This is important because it represents the starting value of our loop.  In almost ALL cases, you will want to start your variable at 0 because when using loops, you'll be looping over an array, and when using arrays, the first value has an index of &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next up, let's talk about the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First off, the value of &lt;code&gt;100&lt;/code&gt; is entirely arbitrary, and generally, you won't be using a hardcoded number like this.  In most cases, you'll replace &lt;code&gt;100&lt;/code&gt; with something like &lt;code&gt;blogPosts.length&lt;/code&gt; for reasons that will become apparent soon.&lt;/p&gt;

&lt;p&gt;Second, it is important to understand what this statement is saying.  I call it a "stop condition" because the loop will continue until &lt;code&gt;i&lt;/code&gt; reaches a value of &lt;code&gt;100&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;How does &lt;code&gt;i&lt;/code&gt; reach &lt;code&gt;100&lt;/code&gt; you might ask?  Well that's where &lt;code&gt;i++&lt;/code&gt; comes in.  If you remember from the prior lesson of this series when we talked about arithmetic operators, using &lt;code&gt;i++&lt;/code&gt; increments the value of &lt;code&gt;i&lt;/code&gt; by 1.  Let's look at the code one more time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// This line will run 100 times and each time, i will increase by 1&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The value of i is: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead and open your browser dev tools (remember, right click anywhere in the browser, click "Inspect Element", and then select "Console") and paste this code in there.&lt;/p&gt;

&lt;p&gt;Although your browser console will print 100 lines in less than a second, the computer is "iterating" through this loop and doing the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check if the value of &lt;code&gt;i&lt;/code&gt; is less than &lt;code&gt;100&lt;/code&gt;.  If so, continue to the code inside the loop.&lt;/li&gt;
&lt;li&gt;Run the code in the loop&lt;/li&gt;
&lt;li&gt;Return to step 1&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like I said, loops are not all that useful on their own, but once we start "iterating" (this is just a fancy word programmers use) over a list of blog posts, users, notifications, or whatever else you can think of, they become very useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are functions in JavaScript?
&lt;/h2&gt;

&lt;p&gt;And finally, we've reached the point in our journey where we can start doing some really cool things with JavaScript.&lt;/p&gt;

&lt;p&gt;Like I have been doing throughout this series, I'm going to introduce you to the basics (and most important parts) of functions and leave out the complicated details.  We will cover the complicated details in our practice exercises and as they come up later in the series, but for now, I think they create unnecessary confusion.&lt;/p&gt;

&lt;p&gt;Here is how you write a function in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// do something here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like I said, there are a lot of things we &lt;em&gt;could&lt;/em&gt; talk about here, but I'm going to keep it to the most important things.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to write and "call" a function
&lt;/h3&gt;

&lt;p&gt;The first thing that you need to know about functions is this–there is a huge difference between "declaring" and "calling" a function.&lt;/p&gt;

&lt;p&gt;We talked extensively about "declaring" and "assigning" variables in prior lessons, and while this is similar, the major difference is that functions don't get declared and called in the same step.&lt;/p&gt;

&lt;p&gt;To see this in action, write the following code into your browser dev tools Console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened?  If you answered "nothing", you are correct.  This doesn't do anything that our eyes can see.  We have indeed done something though...&lt;/p&gt;

&lt;p&gt;We have talked about declaring variables in the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// After declaring and assigning, we can see the type of this variable&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we declare a function, we can do the same thing!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is because our console will store &lt;code&gt;myFunction&lt;/code&gt; in memory just like it stores &lt;code&gt;myVariable&lt;/code&gt; in memory.&lt;/p&gt;

&lt;p&gt;If we can retrieve the function from memory, how do we "call" it?  Another way to say this is how do we "invoke" it?&lt;/p&gt;

&lt;p&gt;To "call" or "invoke" a function, you write the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declaring the function&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "calling" or "invoking" the function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead, try running the code in your browser.  It should print &lt;code&gt;hello&lt;/code&gt; to your console.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's add some parameters and arguments to our function
&lt;/h3&gt;

&lt;p&gt;The function we just wrote is pretty useless.  I wouldn't recommend presenting it in a job interview.&lt;/p&gt;

&lt;p&gt;So how do we make these functions more exciting?  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By adding "parameters" and "arguments".&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm going to show you and then we are going to get into a long-winded discussion about how it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;param2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;param1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;param2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Invocation&lt;/span&gt;
&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're attentive, you'll probably recognize that &lt;code&gt;param1&lt;/code&gt; somehow relates to &lt;code&gt;20&lt;/code&gt; and &lt;code&gt;param2&lt;/code&gt; somehow relates to &lt;code&gt;10&lt;/code&gt;.  You're 100% correct, but let's explore &lt;em&gt;how&lt;/em&gt; they are related.&lt;/p&gt;

&lt;p&gt;When we &lt;em&gt;declare&lt;/em&gt; a JavaScript function, we have the ability to pass zero to infinity number of "parameters" (although most developers agree that 3-5 is the maximum number of parameters a function &lt;em&gt;should&lt;/em&gt; have).  In this case, we passed in 2: &lt;code&gt;param1&lt;/code&gt; and &lt;code&gt;param2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;How did I know to use the names &lt;code&gt;param1&lt;/code&gt; and &lt;code&gt;param2&lt;/code&gt;?  It doesn't matter, because these are completely arbitrary.  I can name these whatever I want.  Below, I changed the parameter names.  Try to run the code below and see what happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;param1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;param2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Invocation&lt;/span&gt;
&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason the code above does not run (throws a &lt;code&gt;ReferenceError&lt;/code&gt;) is because while we have changed the name of the parameters, we forgot to update the &lt;em&gt;references&lt;/em&gt; to the parameters within the function.  Here is the correct way to write it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// I updated this line&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Invocation&lt;/span&gt;
&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's stay on this point for a minute.  Clearly, I am &lt;em&gt;referencing&lt;/em&gt; my parameters from within the function, but how do I know what they represent?&lt;/p&gt;

&lt;p&gt;Well this is where the &lt;em&gt;invocation&lt;/em&gt; part comes in.  Notice at the bottom of my code how I have passed values of &lt;code&gt;20&lt;/code&gt; and &lt;code&gt;10&lt;/code&gt; in as something we call "arguments".&lt;/p&gt;

&lt;p&gt;You can think of "parameters" and "arguments" as two sides of the same coin.  Developers will often use them interchangeably, but for our discussion, the distinction matters.&lt;/p&gt;

&lt;p&gt;By declaring parameters, you are telling the computer, "Hey computer!  When I call this function later in my code, I'm going to pass in two arguments, so make sure you remember them when I do!"&lt;/p&gt;

&lt;p&gt;And by "passing arguments", you are telling the computer, "Hey computer! Remember those parameters I told you about when I wrote &lt;code&gt;myFunction&lt;/code&gt;?  Good, because here are the arguments that I want to use in their place for this function invocation.  I want to replace &lt;code&gt;firstNumber&lt;/code&gt; with &lt;code&gt;20&lt;/code&gt; and &lt;code&gt;secondNumber&lt;/code&gt; with &lt;code&gt;10&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  A brief introduction to "scope"
&lt;/h3&gt;

&lt;p&gt;Try running the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// I updated this line&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Invocation&lt;/span&gt;
&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're gonna get a big fat error that says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught ReferenceError: firstNumber is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will be talking more about "scope" throughout the series, but for now, just remember that not all variables can be &lt;em&gt;accessed&lt;/em&gt; from all places in your code.&lt;/p&gt;

&lt;p&gt;The variables &lt;code&gt;firstNumber&lt;/code&gt; and &lt;code&gt;secondNumber&lt;/code&gt; can only be accessed from &lt;em&gt;within&lt;/em&gt; the function, &lt;code&gt;myFunction&lt;/code&gt;.  This is by design.&lt;/p&gt;

&lt;p&gt;Here's how I think about function scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;param2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;param3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Any code that you write between the opening bracket {&lt;/span&gt;
  &lt;span class="c1"&gt;// and the closing bracket } will have access to the &lt;/span&gt;
  &lt;span class="c1"&gt;// parameters (which are just variables).  In other words,&lt;/span&gt;
  &lt;span class="c1"&gt;// any code here can use `param1`, `param2`, and `param3`,&lt;/span&gt;
  &lt;span class="c1"&gt;// but once we step outside of this area, these cannot be &lt;/span&gt;
  &lt;span class="c1"&gt;// accessed anymore&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// This is NOT VALID because we are trying to access&lt;/span&gt;
&lt;span class="c1"&gt;// `param1` outside of its "scope"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;param1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think that's enough for one day about scope.  JavaScript is full of weird "scope" issues that are distracting to our main focus.  We will cover them later as they arise, but no need at the moment.&lt;/p&gt;

&lt;h3&gt;
  
  
  We can declare and invoke a function simultaneously
&lt;/h3&gt;

&lt;p&gt;All this time, I've been telling you that functions are declared and "called" or "invoked" in &lt;em&gt;separate&lt;/em&gt; steps.&lt;/p&gt;

&lt;p&gt;This is true most of the time, but there is a way to do it all at once.  This is called an "immediately invoked function".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead and run that code in your console.  It should print &lt;code&gt;hello&lt;/code&gt;.  Like I said, this is not often used while programming, but occasionally good to know.  All we are doing is skipping a step.&lt;/p&gt;

&lt;h3&gt;
  
  
  There is another way to write a function in JavaScript
&lt;/h3&gt;

&lt;p&gt;I've been withholding information from you for the last couple minutes.  There is another way to write a function in JavaScript.&lt;/p&gt;

&lt;p&gt;Here it is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a closer look, here is how we did it before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For our learning purposes right now, these are &lt;strong&gt;functionally equivalent&lt;/strong&gt;.  There is a subtle difference, but it brings in a concept called "hoisting" which is confusing to even an experienced JS dev, and I believe getting into it is destructive to our learning experience.  You can "call" the first example above the same way you "call" the second example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What we did here was declare an "anonymous" function and assign it to a variable.  This is what an anonymous function is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you tried to run this anonymous function in your dev tools console, it would throw the following error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uncaught SyntaxError: Function statements require a function name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you might infer, when we are declaring a function on its own, we need to give it a name.  Otherwise, how will we refer back to it??&lt;/p&gt;

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

&lt;p&gt;The topic of "anonymous functions" brings us to our &lt;strong&gt;final&lt;/strong&gt; way of writing functions.  This one is going to be a bit tricky, so brace yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What I have written above is called an "arrow function", and it is another form of an anonymous function.  Just like our anonymous function example above, we cannot run these alone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This doesn't work&lt;/span&gt;
&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this "arrow function" might look more complicated than the conventional "anonymous function", there are only a few differences.  Go ahead, look at them side by side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myAnonymousFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArrowFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get from anonymous to arrow, just remove &lt;code&gt;function&lt;/code&gt; and insert &lt;code&gt;=&amp;gt;&lt;/code&gt; between &lt;code&gt;()&lt;/code&gt; and &lt;code&gt;{&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You might ask &lt;em&gt;why&lt;/em&gt; we have both of these.  Arrow functions didn't exist prior to ES6 (remember from lesson 2 when we talked about ECMAScript standards?).  They were introduced in the ES6 standard (in 2015) because an arrow function &lt;strong&gt;is easier to write&lt;/strong&gt;.  Once you start coding larger projects, you'll realize that these arrow functions are much easier to use and I would recommend getting to know them well.&lt;/p&gt;

&lt;p&gt;There are some other benefits relating to these arrow functions, but once again, talking about them will get us into advanced territory we're not ready for yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's talk about return values
&lt;/h3&gt;

&lt;p&gt;The function that we've been looking at so far has not had a return value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we invoke it with &lt;code&gt;myFunction()&lt;/code&gt;, it prints &lt;code&gt;hello&lt;/code&gt; to the console.  Now, let's assign the result of this invocation to a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ????&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What does &lt;code&gt;result&lt;/code&gt; equal?  &lt;/p&gt;

&lt;p&gt;The correct answer is &lt;code&gt;undefined&lt;/code&gt; because our function doesn't return a value.  Returning a value is simple; just put a &lt;code&gt;return&lt;/code&gt; statement at the end of your function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// hello&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, our &lt;code&gt;result&lt;/code&gt; variable will be set equal to the return value of the function, which is a string, &lt;code&gt;hello&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Whatever comes &lt;em&gt;after&lt;/em&gt; the return statement will not be executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;someNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;someNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;someNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// will never get here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we are returning &lt;code&gt;someNumber&lt;/code&gt; &lt;em&gt;prior&lt;/em&gt; to re-assigning it, our &lt;code&gt;result&lt;/code&gt; variable will be equal to &lt;code&gt;200&lt;/code&gt; because we will never reach the statement &lt;code&gt;someNumber = 100&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions and Objects together
&lt;/h2&gt;

&lt;p&gt;As you have seen in this lesson, you can assign functions to variables and then execute them using the variable name.&lt;/p&gt;

&lt;p&gt;In prior lessons, we showed how you can assign variables to object data type properties.  Quick review:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;quantity&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also assign functions to properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;functionProp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;functionProp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is going to take us a minute to comprehend, but I promise you, I'm showing it to you for a very specific reason.&lt;/p&gt;

&lt;p&gt;The first part is simple.  We define a function that returns a value of &lt;code&gt;20&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second part is a bit trickier.  We are creating an object called &lt;code&gt;myObject&lt;/code&gt; and assigning our newly created function &lt;code&gt;myFunction&lt;/code&gt; to a property called &lt;code&gt;functionProp&lt;/code&gt;.  Again, these are all arbitrary names.  We could have named them differently.&lt;/p&gt;

&lt;p&gt;If you remember, we access properties of an object with "dot notation".  To access the function (&lt;code&gt;myFunction&lt;/code&gt;) stored within the object, we must use &lt;code&gt;myObject.functionProp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And finally, we need to "invoke" or "call" this function, so we need to add &lt;code&gt;()&lt;/code&gt; at the end of this.  Here is a longer way to write the same code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declare the function&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunction&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Declare the object, assign the function to a property of the object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;functionProp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Get the function from the object property&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;functionFromObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;functionProp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// "invoke" or "call" the function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;functionFromObject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Print the return value of the function&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, this code is more complex than it needs to be.  We could easily just call the function directly.&lt;/p&gt;

&lt;p&gt;I wanted to show you this so the next section is a bit more clear.&lt;/p&gt;

&lt;h3&gt;
  
  
  Built-in JavaScript Functions
&lt;/h3&gt;

&lt;p&gt;As a programming language, JavaScript comes with several built-in functions that we can use in our code.  These built-in functions help us modify the values of our variables.  Here is an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// hello world&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// HELLO WORLD&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Believe it or not, &lt;code&gt;myString.toUpperCase()&lt;/code&gt; is similar to &lt;code&gt;myObject.functionProp()&lt;/code&gt; in the code from the previous section.&lt;/p&gt;

&lt;p&gt;You might say, "but a string variable is not an object!".&lt;/p&gt;

&lt;p&gt;You would be correct in saying this.  A string is not an object in JavaScript.  A string doesn't have properties like an object does.&lt;/p&gt;

&lt;p&gt;JavaScript experts would yell at me for this, but just think of the JavaScript built-in methods as function properties of different types of variables.  This is not technically correct, but once again, discussing the nuances will get us into far too advanced topics for now.&lt;/p&gt;

&lt;p&gt;You can chain these built-in methods together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ['HELLO', 'WORLD']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we first capitalize every letter in our string using &lt;code&gt;toUpperCase()&lt;/code&gt;, and then &lt;code&gt;split(" ")&lt;/code&gt; our string by a space delimiter &lt;code&gt;" "&lt;/code&gt; and place the resulting two strings into an array.&lt;/p&gt;

&lt;p&gt;These built-in methods are categorized based on the data type of your variable.  Here are a few examples for each.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// String functions&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Makes entire string uppercase&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Replaces first occurrence of s with l&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;s&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;l&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// SOME STRING&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// lome string&lt;/span&gt;

&lt;span class="c1"&gt;// Number functions&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;41.6978&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// changes the number to a different decimal precision&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;number1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toPrecision&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 41.7&lt;/span&gt;

&lt;span class="c1"&gt;// Array functions&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Finds the index of the value in the array&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are just a few examples to demonstrate and get you familiar with using the built-in methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.tutorialspoint.com/javascript/javascript_builtin_functions.htm"&gt;Here is a link&lt;/a&gt; to all of the built-in JavaScript functions, but please do not read this and try to memorize them.  You can always look them up and we will cover a few in our coding challenges!&lt;/p&gt;

&lt;h2&gt;
  
  
  Combining everything together
&lt;/h2&gt;

&lt;p&gt;Like I have mentioned many times, there is a lot more to JavaScript than what I've taught you in the last three lessons.  That said, we have planted a tree, and now, you just have to fill in the branches and leaves.&lt;/p&gt;

&lt;p&gt;The best way to do that is through exercises, so for the remainder of the post, we will be going through JavaScript exercises together.  I have chosen 25 exercises that will help us fill some of our knowledge gaps, and I'll do my best to point these out as we see them.&lt;/p&gt;

&lt;h2&gt;
  
  
  25 JavaScript Exercises
&lt;/h2&gt;

&lt;p&gt;To get the most out of these challenges, I recommend watching my YouTube video where I solve all of them with you.  I walk you through my thought process and hopefully fill in some gaps from these lessons.&lt;/p&gt;

&lt;p&gt;Here are the challenges and solutions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Solutions - &lt;a href="https://youtu.be/sqRk0Ly66Ps"&gt;YouTube video&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Challenge Collection - &lt;a href="https://www.codewars.com/collections/lesson-5-practice-challenges-number-fullstackroadmap"&gt;Lesson 5 Collection on Codewars&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Lesson 4 - JavaScript Operators (Fullstack developer roadmap series)</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Sat, 02 Jan 2021 02:30:13 +0000</pubDate>
      <link>https://dev.to/zachgoll/lesson-4-javascript-operators-fullstack-developer-roadmap-series-3c1i</link>
      <guid>https://dev.to/zachgoll/lesson-4-javascript-operators-fullstack-developer-roadmap-series-3c1i</guid>
      <description>&lt;h2&gt;
  
  
  I'm on YouTube
&lt;/h2&gt;

&lt;p&gt;If you get tired of reading...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=z8gtbI-LbQE&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq&amp;amp;index=5"&gt;See this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;This is part of my full-stack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first full-stack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please share this series with the hashtag &lt;strong&gt;#fullstackroadmap&lt;/strong&gt; and help me spread the word!&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back.  This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/zg_dev"&gt;My Twitter Profile&lt;/a&gt; - Where you can stay updated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The goal for this lesson
&lt;/h2&gt;

&lt;p&gt;By the end of this lesson, I want you to be able to read the following code and understand exactly what is happening.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;firstNumber&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While knowing variables (last lesson) and operators (this lesson) alone will not get you very far, they are extremely important parts of JavaScript to understand that will set you up for the next couple of lessons where we will get into things like loops, conditionals, and functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are JavaScript Operators?
&lt;/h2&gt;

&lt;p&gt;We briefly worked with operators in the prior lesson, but I didn't explain anything about them.  Operators aren't unique to JavaScript.  In &lt;strong&gt;ANY programming language that you choose,&lt;/strong&gt; there will be a series of operators, and these operators are often split into the following categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arithmetic&lt;/li&gt;
&lt;li&gt;Assignment&lt;/li&gt;
&lt;li&gt;Comparison&lt;/li&gt;
&lt;li&gt;Logical&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Do I have to memorize these categories?
&lt;/h3&gt;

&lt;p&gt;No, and you won't even have to memorize the operators themselves.  A handful of them will become second nature to you rather quickly and the rest will probably not be used much at all.  Remember, you can always use &lt;a href="https://www.w3schools.com/js/js_operators.asp"&gt;Google to remember them.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Arithmetic Operators
&lt;/h3&gt;

&lt;p&gt;Addition, subtraction, multiplication, and division are pretty straightforward.  You'll use &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, and &lt;code&gt;/&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strVar1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;strVar2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Zach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numVar1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numVar2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Addition of numbers&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numVar1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;numVar2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 22&lt;/span&gt;

&lt;span class="c1"&gt;// Addition of strings (also called "concatenation")&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strVar1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;strVar2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints "My name is Zach"&lt;/span&gt;

&lt;span class="c1"&gt;// Subtraction&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numVar1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;numVar2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 18&lt;/span&gt;

&lt;span class="c1"&gt;// Multiplication&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numVar1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;numVar2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 40&lt;/span&gt;

&lt;span class="c1"&gt;// Division&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numVar1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;numVar2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aside from the obvious ones, here are the other arithmetic operators.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modulus - &lt;code&gt;%&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Increment - &lt;code&gt;++&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Decrement - &lt;code&gt;--&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Exponent - &lt;code&gt;**&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here's how they work (make sure to read the comments).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
  Modulus Operator

  This might seem useless to you right now, but there are many times where this can come in handy.
  This will calculate the remainder of a division problem.
*/&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 0 because 2 is a factor of 18&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 2 because 4 goes into 18 four times (4 x 4 == 16), with a remainder of 2&lt;/span&gt;

&lt;span class="cm"&gt;/*
  Increment operator

  This is often used in loops (we will learn about this soon), and will add 1 to a variable
*/&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;myNum&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Equivalent to `myNum = myNum + 1;`&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myNum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 1&lt;/span&gt;

&lt;span class="cm"&gt;/*
  Decrement operator

  You probably won't use this much.  Works opposite to the increment operator.
*/&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;myNum&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Equivalent to `myNum = myNum - 1;`&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myNum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 0&lt;/span&gt;


&lt;span class="cm"&gt;/*
  Exponentiation operator

  Raises the value to a desired exponent
*/&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 64&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Assignment Operators
&lt;/h3&gt;

&lt;p&gt;Remember from the &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/3-javascript-variables/"&gt;previous lesson&lt;/a&gt; when we talked about how a variable must first be &lt;strong&gt;declared&lt;/strong&gt;, and then &lt;strong&gt;assigned&lt;/strong&gt;?  When we talk about "assignment" operators, we are talking about the same concept.&lt;/p&gt;

&lt;p&gt;And really, there is only one assignment operator, and we've already learned about it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you catch what it is?  The &lt;code&gt;=&lt;/code&gt; is an assignment operator.  There are other assignment operators such as &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, &lt;code&gt;*=&lt;/code&gt;, &lt;code&gt;/=&lt;/code&gt;, &lt;code&gt;%=&lt;/code&gt;, and &lt;code&gt;**=&lt;/code&gt;, but you will never NEED them, and quite honestly, I wouldn't recommend using them in most cases.  Here is why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Does the above code make sense to you?  It should–no trick questions going on here.  The above code is simple and self-explanatory.  Now, look at the following code, which does the EXACT SAME THING as the code above, but uses one of these fancy assignment operators.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my opinion, you're not gaining much by using the fancier operator, &lt;code&gt;+=&lt;/code&gt;.  So feel free to memorize all these additional operators, but &lt;code&gt;=&lt;/code&gt; should work just fine for you no matter how skilled of a developer you become.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comparison Operators
&lt;/h3&gt;

&lt;p&gt;In my opinion, comparison operators are the most difficult operators to understand, and can often behave in unexpected ways.  Before we get into each of them, I want to explain how a JavaScript expression is evaluated.  Consider the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will "evaluates" to &lt;code&gt;true&lt;/code&gt;, which if you remember, is a boolean value.  In this case, we are comparing two &lt;em&gt;literal&lt;/em&gt; number values.  We could also do this with two variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;var1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;var2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;var2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same thing, different look.&lt;/p&gt;

&lt;p&gt;If you remember from the previous lesson, we talked about the "left side" vs. "right side" of the &lt;code&gt;=&lt;/code&gt;.  This is where that concept comes into play.  Let's look at something a bit more confusing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're probably sitting there with the following thought–"Huh?...".&lt;/p&gt;

&lt;p&gt;Yes, the above code is valid JavaScript, and quite frankly, it's pretty common to see something like this.  The key to understanding this is to &lt;strong&gt;keep the concept of "left of the equals sign" and "right of the equals sign" clear in your head.&lt;/strong&gt;  Let's look at it again, but this time, paying attention to this left vs. right concept.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// (1)             (2)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// (1) - The variable&lt;/span&gt;
&lt;span class="c1"&gt;// (2) - The expression to evaluate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we are &lt;em&gt;evaluating&lt;/em&gt; the expression to the right of the &lt;code&gt;=&lt;/code&gt;, which resolves to a single boolean value of &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Think of it this way–a JavaScript statement like the one above happens in two steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Everything to the right of &lt;code&gt;=&lt;/code&gt; is evaluated&lt;/li&gt;
&lt;li&gt;The value from step 1 is saved into the variable left of &lt;code&gt;=&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this example, we first need to evaluate &lt;code&gt;20 === 20&lt;/code&gt;, and then, we take the result and assign it to the &lt;code&gt;result&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;At this point, I think we are ready to jump in and look at the &lt;strong&gt;comparison operators&lt;/strong&gt; in JavaScript.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Not all equals signs are created equal.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;=&lt;/code&gt; is very different from &lt;code&gt;==&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;=&lt;/code&gt; is an &lt;em&gt;assignment&lt;/em&gt; operator (discussed above) while &lt;code&gt;==&lt;/code&gt; is a comparison operator.&lt;/p&gt;

&lt;p&gt;Here is a list of all the equality operators.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; - equal value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;===&lt;/code&gt; - equal value AND equal data type&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!=&lt;/code&gt; - not equal value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!==&lt;/code&gt; - not equal value AND no equal data type&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you can understand the first two, you can understand the last two.  Let's go through some examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;300&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When looking at this example, remember two things.  First, remember &lt;em&gt;what&lt;/em&gt; we are evaluating here.  We are evaluating the expression &lt;code&gt;300 == '300'&lt;/code&gt;, and then &lt;em&gt;assigning&lt;/em&gt; the result of this expression to the variable called &lt;code&gt;result&lt;/code&gt;.  Second, notice how &lt;code&gt;300&lt;/code&gt; is a number data type and &lt;code&gt;'300'&lt;/code&gt; is a string data type.&lt;/p&gt;

&lt;p&gt;Since we are using &lt;code&gt;==&lt;/code&gt;, we ONLY care about the value.  We don't care about the data type, and therefore, our expression (that is assigned to &lt;code&gt;result&lt;/code&gt;) will evaluate to &lt;code&gt;true&lt;/code&gt;.  Here's how we break this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;300&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is only one difference here.  Can you spot it?  Well of course, we substituted &lt;code&gt;===&lt;/code&gt; in place of &lt;code&gt;==&lt;/code&gt;.  Now, JavaScript cares about both the value &lt;em&gt;and&lt;/em&gt; the data type.  The value of both variables are the same, but as you can see with our &lt;code&gt;typeof&lt;/code&gt; expressions, the types are not.&lt;/p&gt;

&lt;p&gt;When writing JavaScript, I recommend being as explicit as possible, and therefore, I don't recommend using &lt;code&gt;==&lt;/code&gt; unless you have a specific reason to do so (which is rare).  Take a look at the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;300&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// string&lt;/span&gt;

&lt;span class="c1"&gt;// Remember...&lt;/span&gt;
&lt;span class="c1"&gt;// (1) - Left side of `=` represents the variable&lt;/span&gt;
&lt;span class="c1"&gt;// (2) - Right side of `=` represents the expression that will be evaluated&lt;/span&gt;
&lt;span class="c1"&gt;//   (1)                 (2)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstVar&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;secondVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you remember from the previous lesson, JavaScript has a built-in function called &lt;code&gt;Number()&lt;/code&gt; that we can use to &lt;strong&gt;explicitly coerce&lt;/strong&gt; a string to a number data type.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;result1&lt;/code&gt;, JavaScript &lt;strong&gt;implicitly&lt;/strong&gt; (does it for us) coerces &lt;code&gt;secondVar&lt;/code&gt; from a string to a number, and &lt;em&gt;then&lt;/em&gt; evaluates the expression.  In &lt;code&gt;result2&lt;/code&gt;, JavaScript does not do any coercion and evaluates the expression immediately, which results in a &lt;code&gt;false&lt;/code&gt; value because &lt;code&gt;firstVar&lt;/code&gt; is a number while &lt;code&gt;secondVar&lt;/code&gt; is a string.  In &lt;code&gt;result3&lt;/code&gt; and &lt;code&gt;result4&lt;/code&gt;, we are &lt;strong&gt;explicitly&lt;/strong&gt; coercing &lt;code&gt;secondVar&lt;/code&gt; from a string to a number &lt;em&gt;before&lt;/em&gt; evaluating the expression.  Since in both cases, the data type &lt;em&gt;and&lt;/em&gt; the value are equal, it doesn't matter whether we use &lt;code&gt;==&lt;/code&gt; or &lt;code&gt;===&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Zoom out&lt;/strong&gt;–We just got really detailed, and I want to back up and reassure you that it is okay if you are getting a little lost here.  Our coding exercises at the end of this post will help clarify some of the confusion, and over time, you'll catch on to this stuff.  Don't sweat it yet.&lt;/p&gt;

&lt;h4&gt;
  
  
  What about the other data types?
&lt;/h4&gt;

&lt;p&gt;You can also use &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt; to compare data types other than numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringValue1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringValue2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stringValue1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;stringValue2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;booleanValue1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;booleanValue2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;booleanValue1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;booleanValue2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But... Once we get into objects and arrays, these comparison operators don't work.  Try running the following code in your dev tools console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both arrays and both objects we are comparing look the same don't they?  Well, JavaScript can be tricky sometimes (you'll hear this statement a lot), and comparing the equality of arrays and objects is a bit more complex.  We won't be diving into this, but if you are curious, &lt;a href="https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript"&gt;here is why you can't compare an array&lt;/a&gt; and &lt;a href="https://stackoverflow.com/questions/201183/how-to-determine-equality-for-two-javascript-objects"&gt;here is why you can't compare an object&lt;/a&gt;.  Many developers will use a library such as &lt;a href="https://lodash.com/"&gt;Lodash&lt;/a&gt; to make these comparisons (but this is too advanced for us at this point).&lt;/p&gt;

&lt;p&gt;Alright, moving on to the &lt;em&gt;inequality&lt;/em&gt; operators, &lt;code&gt;!=&lt;/code&gt; and &lt;code&gt;!==&lt;/code&gt;.  They work the same as &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt;, but in reverse.  I won't spend too much time on them, but here are a few examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;In addition to &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;, and &lt;code&gt;!==&lt;/code&gt;, we can also use numeric comparison operators such as &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;=&lt;/code&gt;.  As you might guess, these operators allow us to compare two numbers and represent greater than, greater or equal to, less than, and less than or equal to respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Yep, this is new to us.  You can actually combine variables in a single console.log statement by using commas&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true true true true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The dreaded "ternary" operator
&lt;/h4&gt;

&lt;p&gt;I say "dreaded" because some developers love this operator while others think it overly complicates things.  In my opinion, this operator will save you some time once you have been doing this for a while, but is not necessary at the beginning of your coding journey.&lt;/p&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 javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the values match!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the values do not match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// the values match!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Say what?...&lt;/p&gt;

&lt;p&gt;Although we have not covered the topic of &lt;em&gt;conditionals&lt;/em&gt; in JavaScript yet, take a look at this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the values match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the values do not match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While the code above might not be totally clear, you can probably see what's going on.  And believe it or not, both of the code blocks above are equivalent.  Let's look at that &lt;strong&gt;ternary operator&lt;/strong&gt; once more with some annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//      (1)       (2)              (3)                      (4)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the values match!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the values do not match&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// (1) The variable to assign the expression value to&lt;/span&gt;
&lt;span class="c1"&gt;// (2) The main expression&lt;/span&gt;
&lt;span class="c1"&gt;// (3) The value to assign if the main expression evaluates to true&lt;/span&gt;
&lt;span class="c1"&gt;// (4) The value to assign if the main expression evaluates to false&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// the values match!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are 3 important "tokens" in this JavaScript statement.  We know what &lt;code&gt;=&lt;/code&gt; does, but &lt;code&gt;?&lt;/code&gt; and &lt;code&gt;:&lt;/code&gt; are actually part of the "ternary operator".&lt;/p&gt;

&lt;p&gt;Please don't sweat over this now.  We will have plenty of time to review it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Logical Operators
&lt;/h3&gt;

&lt;p&gt;And the final category that we need to cover is logical operators, which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; - Represents "and"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;||&lt;/code&gt; - Represents "or"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!&lt;/code&gt; - Represents "not"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes, when writing code, we need to evaluate multiple expressions at once.  For example, I might want to check if the user is logged in AND has sufficient permissions to visit a certain page on my app.  I can use the "and" &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator to evaluate that.  It might look something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isUserLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doesUserHavePermission&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canUserPerformAction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isUserLoggedIn&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;doesUserHavePermission&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;canUserPerformAction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a simplified way to write that code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isUserLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doesUserHavePermission&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// When evaluating boolean values, we don't need to use `===`&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canUserPerformAction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isUserLoggedIn&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;doesUserHavePermission&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;canUserPerformAction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both code blocks do the same thing, but the second is more concise.&lt;/p&gt;

&lt;p&gt;Here are a few more examples utilizing all the logical operators.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;booleanValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;booleanValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me walk through one of these piece by piece.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are the steps that the computer goes through when reading this line of code.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First off, what does &lt;code&gt;20 === 20&lt;/code&gt; evaluate to?  Well, it evalutes to &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Second, what does &lt;code&gt;20 === 19&lt;/code&gt; evaluate to?  Well, this time, it evaluates to &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Let's combine these two values together with &lt;code&gt;||&lt;/code&gt;.  This represents "or", so we are really asking the question, "do either of the evaluated expressions equal true"?  In this case, the first one does, so the entire expression is &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Since the entire expression is &lt;code&gt;true&lt;/code&gt;, let's assign that to the &lt;code&gt;result&lt;/code&gt; variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After the above example, the &lt;code&gt;||&lt;/code&gt; and &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; ("or", "and") probably make sense to you, but what's with this &lt;code&gt;!&lt;/code&gt;?  Didn't we already look at this when we used &lt;code&gt;!=&lt;/code&gt; and &lt;code&gt;!==&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Well, kind of.  If you place &lt;code&gt;!&lt;/code&gt; at the beginning of an expression, it &lt;em&gt;reverses&lt;/em&gt; the value of that expression.  Let's say that we had the expression &lt;code&gt;20 === 20&lt;/code&gt;.  This obviously evaluates to &lt;code&gt;true&lt;/code&gt;.  Now what if we changed this to &lt;code&gt;!(20 === 20)&lt;/code&gt;.  Now, the expression is &lt;em&gt;reversed&lt;/em&gt;, and equals false.  And why did we have to put &lt;code&gt;()&lt;/code&gt; here?  We had to put parentheses around the entire expression to tell javascript that we want to evaluate it in entirety.  If we just said &lt;code&gt;!20 === 20&lt;/code&gt;, JavaScript will evaluate this as "not 20" equal to 20.  The entire expression still equals &lt;code&gt;false&lt;/code&gt;, but for an entirely different reason that we don't have time to get into here today.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other Operators
&lt;/h3&gt;

&lt;p&gt;So far, we have covered arithmetic, assignment, comparison, and logical operators, but there are actually some additional operators that we can use in JavaScript.  Since we have a lot of ground to cover in this series, I have intentionally excluded them from our lesson here.&lt;/p&gt;

&lt;p&gt;The operators that we didn't talk about are "bitwise" operators and "type" operators.  You probably won't ever use "bitwise" operators, so no need to explore those.  "type" operators include &lt;code&gt;typeof&lt;/code&gt; and &lt;code&gt;instanceof&lt;/code&gt;.  We have already used &lt;code&gt;typeof&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numberVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;numberVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we won't be covering &lt;code&gt;instanceof&lt;/code&gt; yet as it gets us deep into the weeds of JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combining Operators
&lt;/h2&gt;

&lt;p&gt;The real magic of JavaScript happens when we start combining operators together.  Combining operators also gives us an opportunity to clarify our understanding of this "left side of &lt;code&gt;=&lt;/code&gt;" and "right side of &lt;code&gt;=&lt;/code&gt;" concept.  Take a look at the rather confusing code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(((&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it can get even more complicated if we want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;((((&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But here's the deal.  If you ever see something this complicated in somebody's code, &lt;strong&gt;they have done something wrong&lt;/strong&gt;.  You should never have to think this hard to figure out what a JavaScript expression evaluates to.  I'm showing you this to demonstrate that if we pay attention to our order of operations and the meaning of various operators, something like this is possible.&lt;/p&gt;

&lt;p&gt;Let's look at the first example again and see how we got to the answer of &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//      (1)                              (2)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(((&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Remember...&lt;/span&gt;
&lt;span class="c1"&gt;// (1) represents the variable that will store the result of (2)&lt;/span&gt;
&lt;span class="c1"&gt;// (2) represents the expression that we need to evaluate using operators&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To better visualize this, let's split this long expression into several smaller expressions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;complexExpression&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(((&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// "se" for sub-expression&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;step1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trueBoolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;step2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;step3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step6&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;step4&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;step5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step7&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;step6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;complexExpression&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;step7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;complexExpression&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;step7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the order of operations (mathematics concept, not coding concept), we can split our complex expression into pieces.  I have gone from &lt;code&gt;se1&lt;/code&gt; to &lt;code&gt;se7&lt;/code&gt; to demonstrate how we separate each expression into components and then combine them back together.  In this case, &lt;code&gt;se7&lt;/code&gt; should be equivalent to &lt;code&gt;complexExpression&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In reality, if you had to write something this complex, you would probably make your expression simpler than &lt;code&gt;complexExpression&lt;/code&gt;, but more consolidated than &lt;code&gt;step1&lt;/code&gt; through &lt;code&gt;step7&lt;/code&gt; that we did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;We covered a lot here, but if I had one thing for you to leave with, it would be this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remember, right of &lt;code&gt;=&lt;/code&gt; is a JavaScript expression&lt;/li&gt;
&lt;li&gt;A JavaScript expression can be simple like &lt;code&gt;20 &amp;gt; 19&lt;/code&gt;, or complex like &lt;code&gt;20 &amp;gt; 19 &amp;amp;&amp;amp; 2 + 2 === 4&lt;/code&gt;.  No matter how complex it gets, each expression resolves to a &lt;strong&gt;single value&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;That single value is &lt;em&gt;assigned&lt;/em&gt; to the variable on the left side of &lt;code&gt;=&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Order of operations matter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Challenges
&lt;/h2&gt;

&lt;p&gt;And now, it's your turn to put your knowledge to the test.  Pretty soon, we will be moving over to &lt;a href="https://www.codewars.com/users/zachgoll"&gt;CodeWars&lt;/a&gt; for our lesson challenges, but we aren't quite there yet.  Here are 5 challenges to work through before next lesson where we will be talking about JavaScript conditionals.&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 1
&lt;/h3&gt;

&lt;p&gt;Why doesn't this code work?  Try to make it work and guess what the result will be (hint: this is a little bit of a review from last lesson).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numberVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;numberVariable&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;numberVariable&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;numberVariable&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numberVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-4/challenge1-solution.md"&gt;Solution here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 2
&lt;/h3&gt;

&lt;p&gt;Do the following two blocks of code result in the same answer?  If not, which one would you recommend using and why?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firstNumber&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;secondNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-4/challenge2-solution.md"&gt;Solution here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 3
&lt;/h3&gt;

&lt;p&gt;What does &lt;code&gt;expression5&lt;/code&gt; evaluate to?  How could you write this in a single line of code (for exercise purposes only; you would never want to combine all this in one line)?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expression1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expression2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expression3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;expression1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;expression2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expression4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;expression3&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;305&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expression5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;expression4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expression5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-4/challenge3-solution.md"&gt;Solution here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 4
&lt;/h3&gt;

&lt;p&gt;What does &lt;code&gt;result&lt;/code&gt; evaluate to?  You might want to review the previous lesson for this one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;prop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;first value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;prop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prop2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-4/challenge4-solution.md"&gt;Solution here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 5
&lt;/h3&gt;

&lt;p&gt;This one is meant to be a tough challenge.  You probably will need to Google this and it might take you a while to complete.&lt;/p&gt;

&lt;p&gt;What does &lt;code&gt;result&lt;/code&gt; evaluate to?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;nestedObject1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;nestedObject2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;myObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nestedObject1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nestedObject2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-4/challenge5-solution.md"&gt;Solution here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Lesson 3 - JavaScript Variables and Data Types (Fullstack developer roadmap series)</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Thu, 24 Dec 2020 23:18:44 +0000</pubDate>
      <link>https://dev.to/zachgoll/lesson-3-javascript-variables-and-data-types-fullstack-developer-roadmap-series-5flf</link>
      <guid>https://dev.to/zachgoll/lesson-3-javascript-variables-and-data-types-fullstack-developer-roadmap-series-5flf</guid>
      <description>&lt;h2&gt;
  
  
  I'm on YouTube
&lt;/h2&gt;

&lt;p&gt;If you get tired of reading...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=YFVT567KBlw&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq&amp;amp;index=4"&gt;See this lesson on YouTube here&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;This is part of my full-stack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first full-stack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please share this series with the hashtag &lt;strong&gt;#fullstackroadmap&lt;/strong&gt; and help me spread the word!&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back.  This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/zg_dev"&gt;My Twitter Profile&lt;/a&gt; - Where you can stay updated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hold yourself accountable with 100 days of code
&lt;/h2&gt;

&lt;p&gt;Today marks the first lesson where we actually start writing some real code.  Because of this, I encourage you to take the 100 days of code challenge.  This is a challenge created by Alexander Kallaway, who was a guy just like you and me trying to hold himself accountable to learning to code.&lt;/p&gt;

&lt;p&gt;He started #100DaysOfCode on Twitter a few years back, and it has grown into a large community of people learning to code.  Here are the rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write code for at least 1 hour every day.&lt;/strong&gt;  If you have to wake up at 4am and get your hour in before your day job, DO IT.  If you have to stay up an extra hour, DO IT.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tweet your progress&lt;/strong&gt; and encourage at least 2 other people doing the challenge each day.  I'll leave templates for you in each post, and &lt;strong&gt;if you include the hashtag #fullstackroadmap, I'll do my best to like and retweet you!&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Just finished my first lesson of the #fullstackroadmap on JavaScript variables and data types! #100DaysOfCode     &lt;a href="https://ctt.ac/7b54p"&gt;Click to tweet&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  We won't cover everything in JavaScript here
&lt;/h2&gt;

&lt;p&gt;When learning a new coding language, there are many features that one could teach about that language. Some are extremely important while others are likely to be forgotten shortly after you learn them and never used again.&lt;/p&gt;

&lt;p&gt;JavaScript has a lot of features. For example, there are a lot of "shorthand" ways to write JavaScript code as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Oh hey, this is a comment because the line starts with two forward slashes.  It doesn't affect the code&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counterVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Increases the variable by 1&lt;/span&gt;
&lt;span class="nx"&gt;counterVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;counterVariable&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ALSO increases the variable by 1 (this is the shorthand version)&lt;/span&gt;
&lt;span class="nx"&gt;counterVariable&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could certainly try to learn ALL of these neat little features, but I don't think we should. The &lt;strong&gt;last thing that I want&lt;/strong&gt; is for you to get lost in the shiny features of JavaScript and gloss over the things that really matter at the beginning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So you're telling me we're only going to learn a portion of JavaScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YES.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And believe it or not, most employed developers can't claim full understanding of the JavaScript language; hence the popularity of Kyle Simpson's free book series, &lt;a href="https://github.com/getify/You-Dont-Know-JS/tree/1st-ed"&gt;You Don't Know JavaScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While this book has been extremely helpful to my understanding of the JavaScript language, I have to be honest–I learned a lot more from it years after learning to code than I did when first learning to code. The book has an introduction to JavaScript, but in my opinion, it was written for someone who already knows JavaScript and who wants to level up.&lt;/p&gt;

&lt;p&gt;Be sure to reference YDKJS (You Don't Know JavaScript) throughout your career, but in this full-stack series, I'm going to be keeping the technical details of how JavaScript runs behind the scenes to a minimum.  &lt;strong&gt;This is not because I don't want you to learn how JavaScript works&lt;/strong&gt;.  This is so we can focus on things like creating web apps rather than learning everything about JavaScript prototypes and why JavaScript is technically not a class-based language.  These things are important down the road, but in my opinion, create unnecessary confusion when getting started.&lt;/p&gt;

&lt;p&gt;Just like a Finance professional rarely needs to know much more than basic Algebra, a full-stack web developer rarely needs to know more than the basics of a given programming language. &lt;strong&gt;The reason we code is to build useful things&lt;/strong&gt;. And to build useful things, you don't need to be the next JavaScript wizard.&lt;/p&gt;

&lt;p&gt;The most challenging part of becoming a full-stack web developer is not learning the intricacies of a given language but &lt;strong&gt;being able to clearly define your ideas, write them in code, deploy that code, and distribute your product to the people who need it most.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So let's start building.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two important JavaScript concepts
&lt;/h2&gt;

&lt;p&gt;Throughout this series, I'm going to be showing lots of example code snippets. Throughout those snippets, you might see things like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This is a comment&lt;/span&gt;

&lt;span class="cm"&gt;/*
  This is also a comment, and extends 
  to multiple lines
  */&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;the console.log statement prints values to the console&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Comments can be written as a single line or multiple lines, and are often used to describe lines of code. &lt;strong&gt;These do not affect the code.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;console.log()&lt;/code&gt; function is built-in to the JavaScript programming language and allows us to print values to the console. Remember the "Console" from the &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/1-first-program/"&gt;first lesson&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;Go ahead and type out the following program in the Firefox dev tools Console to get a feel for comments and &lt;code&gt;console.log&lt;/code&gt; statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This comment won't affect the console.log statement below&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;but this should print to the console&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Intro to Variables and Data Types
&lt;/h2&gt;

&lt;p&gt;Every programming language has the concept of "variables". In my mind, a variable can be thought of as a "container" for data.&lt;/p&gt;

&lt;p&gt;Think of variables like an Amazon warehouse. The warehouse has thousands of containers filled with various products, and it is meticulously organized so that the robots can find the products when they need to. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy0kfa18dif6qz11axi7e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy0kfa18dif6qz11axi7e.jpg" alt="amazon container" width="400" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A computer is the same way. During the execution of a program (not before, not after), the computer constructs a "warehouse" similar to that of Amazon. It has thousands of "containers" that store different &lt;em&gt;types&lt;/em&gt; of data, and all the while, the computer knows EXACTLY where to find each of these containers.&lt;/p&gt;

&lt;p&gt;Before we get too detailed, let's see a couple of examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourSecondVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourThirdVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;third variable&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead, open up Firefox developer tools, go to the console, and type in these variables! And if you don't know how to get to the console, &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/1-first-program/"&gt;go back to lesson 1&lt;/a&gt; for an intro to dev tools.&lt;/p&gt;

&lt;p&gt;Remember, each of Amazon's containers has different types of products stored in them just like each variable we declare in our code has different types of data stored in them. But before we get into those data types, let's talk about some of these symbols in the code above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pay attention to every "token"
&lt;/h2&gt;

&lt;p&gt;Let's look at the first variable again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you remember from the &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/2-what-is-javascript-and-how-is-it-used/"&gt;previous lesson&lt;/a&gt;, we briefly talked about how our computer doesn't actually understand JavaScript; it only understands 1s and 0s. And to convert this line of code to 1s and 0s, we need to use something called a "compiler" to read through it and translate each character.&lt;/p&gt;

&lt;p&gt;For a few minutes, we are going to think like a compiler, because in programming &lt;strong&gt;every character matters&lt;/strong&gt;. Don't believe me? Try running this in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;learning&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="nx"&gt;gives&lt;/span&gt; &lt;span class="nx"&gt;you&lt;/span&gt; &lt;span class="nx"&gt;superpowers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what happened?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhto5irm3o1skgazh2w77.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhto5irm3o1skgazh2w77.JPG" alt="syntax error" width="702" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look closely at this program and the one a few paragraphs above, and you'll notice that we're missing a &lt;code&gt;'&lt;/code&gt; character, which is causing our &lt;code&gt;SyntaxError&lt;/code&gt;. You'll also notice that the JavaScript debugger calls it a "token", which is generally what we call an individual character in a program whether that be &lt;code&gt;c&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;;&lt;/code&gt;, &lt;code&gt;8&lt;/code&gt;, or &lt;code&gt;'&lt;/code&gt;.  To see all valid characters, you need to refer to something called an &lt;a href="http://www.asciitable.com/"&gt;ASCII Table&lt;/a&gt;. These are all "tokens" and when the computer reads through your code, it is looking at every single token &lt;strong&gt;in a specific order&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As a beginner, you might find it intimidating that you have to pay attention to every single token of your program, but I can assure you, it is not as hard as you might think. Furthermore, a lot of the &lt;a href="https://www.zachgollwitzer.com/posts/2020/which-code-editor-to-learn-first/"&gt;code editors&lt;/a&gt; that you'll be using in future lessons are pretty darn smart these days and will alert you when you've made what we call a "syntactical mistake".&lt;/p&gt;

&lt;p&gt;So now that you know how important every "token" of your code is, let's walk through some important concepts within our line of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Declare, then assign
&lt;/h2&gt;

&lt;p&gt;When working with variables in JavaScript (and most other languages), there are actually two steps required to create and use a variable.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Declaration of the variable&lt;/li&gt;
&lt;li&gt;Assignment of the variable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Take a look at our line of code again. Can you tell where we declare it and where we assign it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;It's a trick question.&lt;/strong&gt; We are actually doing both at once. But if we re-write the program a little bit differently, we might be able to see it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Once again, this is a comment and doesn't affect the code&lt;/span&gt;

&lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Assignment&lt;/span&gt;
&lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code does the same thing as the previous code, but declares and assigns the variable in two steps. You might also notice that instead of &lt;code&gt;const&lt;/code&gt;, we used &lt;code&gt;let&lt;/code&gt;. I'll explain why in a minute, but first, let's conceptualize what's going on here.&lt;/p&gt;

&lt;p&gt;Remember our Amazon analogy? When we create a new container in the warehouse, we need to first register that container (probably with a unique ID). After we have registered the container, the Amazon robots know exactly where to find it. Now that the robots can find the container, we can place products in it! &lt;/p&gt;

&lt;p&gt;The same concept works with programming. You first need to declare a variable so that the computer can allocate a place in memory for it to be stored. Once it has a place to be stored, you can then assign it some data.&lt;/p&gt;

&lt;h3&gt;
  
  
  var, let, const
&lt;/h3&gt;

&lt;p&gt;Now back to the question you're probably asking. Why did we use &lt;code&gt;let&lt;/code&gt; in the second example? To answer that, go ahead and run the following code in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo4r74p8tjwlvh9hmdjkq.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo4r74p8tjwlvh9hmdjkq.JPG" alt="syntax error" width="703" height="58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yet another &lt;code&gt;SyntaxError&lt;/code&gt;. If you're observant, you might have noticed that we are getting a lot of these &lt;code&gt;SyntaxError&lt;/code&gt; errors. That's because when you write improper JavaScript, you are "syntactically incorrect" and the JavaScript debugger will feel no shame in telling you that you're wrong!&lt;/p&gt;

&lt;p&gt;In this case, we are getting an error because there are specific ways that &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; can be used in JavaScript.&lt;/p&gt;

&lt;p&gt;Whenever you write a variable in JavaScript, &lt;strong&gt;you will always place one of these "reserved words" in front of your variable&lt;/strong&gt;. Each of the following lines of code are valid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;variable3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The question becomes, &lt;strong&gt;how do I know when to use each of them?.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  When to use "var"
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Never&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;var&lt;/code&gt; keyword is actually a legacy keyword in JavaScript, and many JavaScript style guides (more on this later) advise programmers to use either &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I am bringing this up because as you read through online tutorials or open-source codebases, you will surely see programs with the &lt;code&gt;var&lt;/code&gt; keyword in them. This usually means that the code was written years ago or the programmer has not caught up with the times.&lt;/p&gt;

&lt;p&gt;The main reason &lt;code&gt;var&lt;/code&gt; is not used anymore is because while using it, variables can be re-declared, which caused a lot of confusion for developers in the past. I will not be getting into the details of this as they become very confusing very quickly and I don't want to distract from what we are learning here.&lt;/p&gt;

&lt;h4&gt;
  
  
  When to use "let"
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;If you expect the value of the variable to be &lt;em&gt;reassigned&lt;/em&gt; during the program, use &lt;code&gt;let&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This probably doesn't make sense yet, but consider the following example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Assignment&lt;/span&gt;
&lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Re-Assignment&lt;/span&gt;
&lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run this code in the console, it is perfectly valid and after running it, the value of your variable will be &lt;code&gt;4&lt;/code&gt; because we "reassigned" it.&lt;/p&gt;

&lt;h4&gt;
  
  
  When to use "const"
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;If you expect the value of the variable to &lt;em&gt;remain the same&lt;/em&gt; during the program, use &lt;code&gt;const&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In all programming languages, there are "constants". These are variables that never change and are often written in all capital letters. For example, if you're writing a program to calculate the circumference of a circle, you might define a constant variable like &lt;code&gt;TAX_RATE = 0.08&lt;/code&gt;. You know this tax rate won't change throughout your program, so you define it as a "constant".&lt;/p&gt;

&lt;p&gt;While there are some technical differences in how the variables are stored between &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;, the true value of using them is to indicate to &lt;em&gt;other programmers&lt;/em&gt; how certain variables are meant to be used. Let's say that I'm reading through someone's code and I see this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Top of the program&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// A bunch of code here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without reading past the first couple lines, I know that somewhere in this program, the variable &lt;code&gt;count&lt;/code&gt; will be re-assigned to a different value, and is NOT a constant variable.  But if I saw the following code, I know that these values aren't going to change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TAX_RATE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.08&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// a bunch of code here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you might ask–why do you capitalize the variable here?  What is the difference between &lt;code&gt;taxRate&lt;/code&gt; and &lt;code&gt;TAX_RATE&lt;/code&gt;?  This makes no &lt;strong&gt;functional&lt;/strong&gt; difference.  It is purely semantic and I am about to explain why we do things like this in programming.  Both of the code blocks below are &lt;strong&gt;functionally identical&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TAX_RATE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.08&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TAX_RATE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Works the same as above!&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;taxRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.08&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's find out why in the next section.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to write a variable
&lt;/h2&gt;

&lt;p&gt;Back to our simple program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we are using &lt;code&gt;const&lt;/code&gt;, we know this variable will never be re-assigned throughout the program, but we haven't talked about the rest of the "tokens" in this line of code.&lt;/p&gt;

&lt;p&gt;The next thing we need to discuss is the proper way to write JavaScript variables. Here are valid ways to write JS variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;your_first_variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;YOUR_FIRST_VARIABLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourfirstvariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;YourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here are &lt;em&gt;invalid&lt;/em&gt; ways to write them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;First&lt;/span&gt; &lt;span class="nx"&gt;Variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;stvariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yourFirstVariable&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can remember the invalid ways to write a JavaScript variable by &lt;strong&gt;treating them like a Twitter hashtag.&lt;/strong&gt; When you write a hashtag on Twitter, the word needs to be all in one piece. If there are spaces in your hashtag, Twitter only recognizes the first word.&lt;/p&gt;

&lt;p&gt;Aside from that rule, there are only a couple "gotchas" to look out for. One not-so-obvious rule is you cannot start your variable with a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This is valid&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// This is NOT valid&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You also cannot use certain characters in a variable such as &lt;code&gt;'&lt;/code&gt;, but I would not spend your time trying to remember all the invalid ways to write a variable because you will catch on quickly and if you write a variable incorrectly, you will see errors in your console that will tell you what you've done wrong.&lt;/p&gt;

&lt;p&gt;Now for the valid ways...&lt;/p&gt;

&lt;p&gt;As you can see above, there are many valid ways to write JavaScript variables, but that doesn't mean you should use them all. Just like we use &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; to indicate to other programmers what type of variable we are dealing with, we can use these different "styles" to communicate as well.&lt;/p&gt;

&lt;p&gt;As you learn programming, you'll come across something called a "Style Guide", which is &lt;strong&gt;a set of guidelines for writing code in a specific language or framework&lt;/strong&gt;. No single style guide is more correct than another, but each company might specify certain ways to write code. For example, here is &lt;a href="https://google.github.io/styleguide/jsguide.html"&gt;Google's JavaScript style guide&lt;/a&gt; while here is &lt;a href="https://github.com/airbnb/javascript"&gt;Airbnb's JavaScript style guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you read through these, you'll notice that they each specify a way to name variables.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://google.github.io/styleguide/jsguide.html#naming-rules-common-to-all-identifiers"&gt;Google naming conventions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/airbnb/javascript#naming-conventions"&gt;Airbnb naming conventions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both guides recommend using &lt;code&gt;camelCase&lt;/code&gt; for naming regular variables, and the JavaScript community as a whole has adopted this convention.&lt;/p&gt;

&lt;p&gt;If you started writing code in the Python coding language, you would see a lot of variables written in &lt;code&gt;snake_case&lt;/code&gt; indicated by the underscores between variable words.&lt;/p&gt;

&lt;p&gt;Some of the most common naming conventions are &lt;code&gt;camelCase&lt;/code&gt;, &lt;code&gt;UpperCamelCase&lt;/code&gt; (also called &lt;code&gt;PascalCase&lt;/code&gt;), &lt;code&gt;snake_case&lt;/code&gt;, &lt;code&gt;CONSTANT_CASE&lt;/code&gt;, and &lt;code&gt;kebab-case&lt;/code&gt;.  Please note, &lt;code&gt;kebab-case&lt;/code&gt; does not work with JavaScript variables, but all the rest do.&lt;/p&gt;

&lt;p&gt;After looking at these style guides, you might be overwhelmed with the quantity of rules that these companies follow when writing their code, but I promise you, employees of Airbnb do not study the style guide for the first 2 weeks of their employment.&lt;/p&gt;

&lt;p&gt;There are tools called "code linters" that can automatically detect when you have improperly implemented a certain style guide. These linters often work inside your code editor and give you feedback as you are writing the code. In the screenshot below, I have improperly used &lt;code&gt;const&lt;/code&gt;, and the linter has let me know that I need to use &lt;code&gt;let&lt;/code&gt; to declare the &lt;code&gt;totalFullRounds&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7eisb8laceo0na12740b.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7eisb8laceo0na12740b.JPG" alt="linter" width="663" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you write more and more code, you will catch on to some of these JavaScript conventions, and we will even set up one of these linters to help us write cleaner code!&lt;/p&gt;

&lt;h3&gt;
  
  
  Name your variables something meaningful
&lt;/h3&gt;

&lt;p&gt;If you haven't caught this yet, you can use anything you want as a variable name.  These are all valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someNumberThatRepresentsTheNumberOfUsersInMyDatabase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numberOfUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While you could use any of these, can you guess which one is best?&lt;/p&gt;

&lt;p&gt;Of course, &lt;code&gt;numberOfUsers&lt;/code&gt; is best because it is short enough to write quickly, but long enough to describe what it represents.  It is often tempting to shorten your variables like &lt;code&gt;q&lt;/code&gt;, but your future self will thank you when you have to read through your old code and figure out what it does.&lt;/p&gt;

&lt;p&gt;I would much rather see you write longer variables that are descriptive than shorter variables that will leave you scratching your head trying to remember what they were for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Left vs. Right - Know the difference
&lt;/h2&gt;

&lt;p&gt;Our program, once again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yourFirstVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;learning to code gives you superpowers&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, we have covered everything on the left side of the "equals" sign. To write a variable, you need to use either &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; followed by 1 space and a variable.&lt;/p&gt;

&lt;p&gt;Before we jump to the other side of &lt;code&gt;=&lt;/code&gt;, we need to understand how variables behave on both sides of it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The left side of the equals sign
&lt;/h3&gt;

&lt;p&gt;Everything left of &lt;code&gt;=&lt;/code&gt; will always be a variable, and will always be the "container" that the values are stored in.&lt;/p&gt;

&lt;p&gt;Please note that we are talking about &lt;code&gt;=&lt;/code&gt;, NOT &lt;code&gt;==&lt;/code&gt; or &lt;code&gt;===&lt;/code&gt;. These will come later in our series, but make a HUGE difference in how the left side behaves.&lt;/p&gt;

&lt;h3&gt;
  
  
  The right side of the equals sign
&lt;/h3&gt;

&lt;p&gt;Everything right of &lt;code&gt;=&lt;/code&gt; represents the &lt;strong&gt;value&lt;/strong&gt; that will be stored in the "container" (left of &lt;code&gt;=&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Going back to our Amazon analogy, think of the left side of &lt;code&gt;=&lt;/code&gt; as the storage container and the right side of &lt;code&gt;=&lt;/code&gt; as the products that go in the container.&lt;/p&gt;

&lt;p&gt;The right side of &lt;code&gt;=&lt;/code&gt; is a bit trickier than the left side because there are many valid things you can put there. While the only thing you can put left of &lt;code&gt;=&lt;/code&gt; is a variable, you can put all of the following things right of &lt;code&gt;=&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Zach&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;variableType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;variableValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, my name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable6&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;variable5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;variable3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead, paste the above code in your dev tools Console. Now, write the following line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It prints "Hello, my name is Zach" because I have actually combined two variables into one.&lt;/p&gt;

&lt;p&gt;Don't worry if you can't understand the above code; it is a bit advanced and we will get there eventually. Let's now dive into the different data types in JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  The semicolon at the end
&lt;/h3&gt;

&lt;p&gt;You might have noticed that at the end of each line, I have been putting a &lt;code&gt;;&lt;/code&gt;. This represents the completion of a JavaScript expression.&lt;/p&gt;

&lt;p&gt;You can technically run JavaScript without a semi-colon at the end of each line, but it is best practice to put it there and will keep you from experiencing odd behaviors caused by omitting it.&lt;/p&gt;

&lt;p&gt;Try running the following code in your browser console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Works right? Now try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It throws an error because you have placed two variable assignments on the same line without telling the compiler when the first assignment ends and when the second begins. This is why the semi-colon matters.&lt;/p&gt;

&lt;p&gt;Please note that it is NOT correct to say "every line ends with a semicolon". The following JavaScript program is syntactically correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;property1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;somevalue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;property2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;anothervalue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To the JavaScript compiler, this is technically one line. You could have also written it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;property1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;somevalue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;property2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;anothervalue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JavaScript Data Types
&lt;/h2&gt;

&lt;p&gt;Teaching the concept of "data types" with JavaScript is often a difficult task because JavaScript is considered a "dynamically typed" coding language.&lt;/p&gt;

&lt;p&gt;Below is some JavaScript code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And below, I have re-written the above code in TypeScript, which is a superset of JavaScript that we may look at (still deciding on this) much later in this series. When I say "superset", I'm referring to the fact that all JavaScript is valid TypeScript, but not all TypeScript is valid JavaScript (and must be "transpiled" into JavaScript to run).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something here?&lt;/p&gt;

&lt;p&gt;In TypeScript, we are specifying what &lt;em&gt;type&lt;/em&gt; of value we are assigning to the variable, while in JavaScript, we just assign it.&lt;/p&gt;

&lt;p&gt;TypeScript is "statically typed" while JavaScript is "dynamically typed". They don't function any differently, but with statically typed languages like TypeScript, Java, C, and C++, we are being much more explicit with our "type checking".&lt;/p&gt;

&lt;p&gt;Since JavaScript is dynamically typed, you might think, "I don't need to worry about data types!". In reality, it is quite the opposite. Because JS is dynamically typed, it is critical that you are paying attention to what types of data you are assigning to your variables and returning from your functions. Many developers prefer to write TypeScript rather than JavaScript (including myself) for this very reason, but we can't start writing TypeScript until we know how to write JavaScript!&lt;/p&gt;

&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;The first type of data is a string. We can write strings in JavaScript in two ways:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;singleQuoteString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;this is a string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubleQuoteString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;this is a string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which one is better? Neither. They both work just fine. But as of the time of writing, most JavaScript developers would recommend using single quotes, and most "Style Guides" (as we talked about earlier) will enforce single quotes for string variables.&lt;/p&gt;

&lt;p&gt;Anything that you put between either single quotes &lt;code&gt;''&lt;/code&gt; or double quotes &lt;code&gt;""&lt;/code&gt; will be treated as a string data type. You can even put other characters and numbers in there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringVariable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am a string with a number: 10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// This is still a string, even though it stores a number in it&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringVariable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;20&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Numbers
&lt;/h3&gt;

&lt;p&gt;Next, we have the number type. This is assigned without any special characters around it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numberVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only thing that you may be tempted to do that is incorrect is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalidNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By placing the &lt;code&gt;,&lt;/code&gt; in the number, you have made a syntax error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flrxyhx2zmvrjkyansxkz.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flrxyhx2zmvrjkyansxkz.JPG" alt="syntax error" width="702" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Booleans
&lt;/h3&gt;

&lt;p&gt;A boolean value is pretty simple to understand–it is either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.  There are no other possible values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trueValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;falseValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Arrays
&lt;/h3&gt;

&lt;p&gt;You can think of an array as a "list" of values.  In JavaScript, you can assign any data type as an array value.  An array is indicated by brackets and comma-separated values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numbersArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;booleanArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mixedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main concept you must understand with arrays is "indexing".  Each value of an array has a specific "index", and the index values always start at 0.  For example, in the following array, the value &lt;code&gt;red&lt;/code&gt; is at index 0, the value &lt;code&gt;green&lt;/code&gt; is at index 1, and the value &lt;code&gt;blue&lt;/code&gt; is at index 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Indexes             0       1        2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you wanted to print a single value of this array, you would reference the appropriate index.  We will get into this more later in the series, but this is how you would print the value &lt;code&gt;red&lt;/code&gt; from the array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;singleArrayValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stringArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;singleArrayValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could have also done this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stringArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Objects
&lt;/h3&gt;

&lt;p&gt;Objects are what JavaScript is built on.  You might hear the phrase that in JavaScript, "everything is an object".  And while I don't want to get into the subtleties of this statement now, I will say that you'll be working with objects quite often.&lt;/p&gt;

&lt;p&gt;You can think of objects as "complex containers".  If we go back to the Amazon analogy, you might imagine a container that has containers within it, and in each container, there are Amazon products waiting to be shipped.  Let's take a look at a simple object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;simpleObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;simpleObject&lt;/code&gt; is the variable we are assigning the object to.  &lt;code&gt;myVariable&lt;/code&gt; is one "property" of the object, and &lt;code&gt;some value&lt;/code&gt; is the value of that property.&lt;/p&gt;

&lt;p&gt;If we wanted to access the value of this property, we would use something called "dot notation":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;simpleObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;valueOfProperty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;simpleObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;valueOfProperty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of it like this–the &lt;code&gt;myVariable&lt;/code&gt; property is a &lt;em&gt;part of&lt;/em&gt; the &lt;code&gt;simpleObject&lt;/code&gt; object, and to access it, we need to first name the object that contains the property, and then the property we want to retrieve, or &lt;code&gt;simpleObject.myVariable&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;You can also access the values of properties similar to how we did with arrays, but in this case, we need to know the property name to access it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;simpleObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Using dot notation to access property value&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;simpleObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Using bracket notation to access property value&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;simpleObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;myVariable&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how I have passed in the string version of my object property to access the value of that property.  This is functionally equivalent to using dot notation.&lt;/p&gt;

&lt;p&gt;Objects can have nested properties too.  For example, take a look at this object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nestedObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;layerOne&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;layerTwo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;layerThree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;layerFour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;layerFive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;theValueWeWant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;here is my value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get &lt;code&gt;theValueWeWant&lt;/code&gt;, we would use "dot notation" to get it using the expression, &lt;code&gt;nestedObject.layerOne.layerTwo.layerThree.layerFour.layerFive.theValueWeWant&lt;/code&gt;.  Go ahead, try running the code below in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nestedObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;layerOne&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;layerTwo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;layerThree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;layerFour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;layerFive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;theValueWeWant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;here is my value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nestedObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layerOne&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layerTwo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layerThree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layerFour&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;layerFive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theValueWeWant&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are far more data types that you can assign to properties of objects, but we will not go into them at this time.&lt;/p&gt;

&lt;p&gt;Also, you might notice how the names of the variables are completely arbitrary.  Properties of objects are written just like a normal variable.&lt;/p&gt;

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

&lt;p&gt;While we have a headline here, I will not be covering the concept of JavaScript functions in this post.  I plan to cover functions and many other JavaScript basics in future posts of this series!&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary and why variables matter
&lt;/h2&gt;

&lt;p&gt;At this point, we have only covered how to declare and assign a JavaScript variable and what types of data can be assigned to a variable.&lt;/p&gt;

&lt;p&gt;With this knowledge, there is actually not much that we can do as programmers.  Variables are critical to every program, but without things like operators, if-then statements, loops, and functions, our variables are no use to us.&lt;/p&gt;

&lt;p&gt;We will soon get to a point where we can write useful code, but for now, just remember the following things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first step is to &lt;em&gt;declare&lt;/em&gt; a variable, then &lt;em&gt;assign&lt;/em&gt; it a value (although we often do it in one step)&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;, NOT &lt;code&gt;var&lt;/code&gt; to declare and assign variables&lt;/li&gt;
&lt;li&gt;The left side of &lt;code&gt;=&lt;/code&gt; represents the variable that will hold the value you are assigning&lt;/li&gt;
&lt;li&gt;There are many ways to write a JavaScript variable, but &lt;code&gt;camelCase&lt;/code&gt; is the preferred way&lt;/li&gt;
&lt;li&gt;There are 5 main types of variables–strings, numbers, booleans, arrays, and objects&lt;/li&gt;
&lt;li&gt;A semicolon represents the end of a JavaScript expression&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Be sure to &lt;a href="https://lists.zachgollwitzer.com/"&gt;get on my email list&lt;/a&gt; to receive updates when I post lessons in the future!&lt;/li&gt;
&lt;li&gt;Tweet one thing you learned in this tutorial with the hashtags #fullstackroadmap and #100DaysOfCode&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Just finished my first lesson of the #fullstackroadmap on JavaScript variables and data types! #100DaysOfCode     &lt;a href="https://ctt.ac/7b54p"&gt;Click to tweet&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Your Homework
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Challenge 1
&lt;/h4&gt;

&lt;p&gt;In the dev tools console, figure out how to do the following (use Google to help):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a boolean variable called &lt;code&gt;myBoolean&lt;/code&gt; and set it to &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a string variable called &lt;code&gt;myString&lt;/code&gt; and set it to &lt;code&gt;hello world&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create a number variable called &lt;code&gt;firstNumber&lt;/code&gt; and set it equal to &lt;code&gt;20&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create another number variable called &lt;code&gt;secondNumber&lt;/code&gt; and set it equal to &lt;code&gt;40&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Re-assign &lt;code&gt;secondNumber&lt;/code&gt; and set it equal to &lt;code&gt;80&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create an array called &lt;code&gt;myArray&lt;/code&gt; and put &lt;code&gt;myBoolean&lt;/code&gt; at index 0, and &lt;code&gt;myString&lt;/code&gt; at index 1.&lt;/li&gt;
&lt;li&gt;Create an object called &lt;code&gt;myObject&lt;/code&gt; and assign &lt;code&gt;myArray&lt;/code&gt; to a property called &lt;code&gt;firstProperty&lt;/code&gt;, and the sum of &lt;code&gt;firstNumber&lt;/code&gt; and &lt;code&gt;secondNumber&lt;/code&gt; to a property called &lt;code&gt;sumProperty&lt;/code&gt; (hint: we didn't cover how to do this here).&lt;/li&gt;
&lt;li&gt;Print &lt;code&gt;myObject&lt;/code&gt; to the console.&lt;/li&gt;
&lt;li&gt;Print the &lt;code&gt;sumProperty&lt;/code&gt; of &lt;code&gt;myObject&lt;/code&gt; to the console.&lt;/li&gt;
&lt;li&gt;Print the value at index 1 of &lt;code&gt;firstProperty&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-3/challenge-1-solution.js"&gt;Solution found here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Challenge 2
&lt;/h4&gt;

&lt;p&gt;There are three things wrong with this code.  Find them and explain why they are wrong.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;some&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;someNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-3/challenge-2-solution.js"&gt;Solution found here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Challenge 3
&lt;/h4&gt;

&lt;p&gt;What does &lt;code&gt;resultVariable&lt;/code&gt; equal?  What data type is it?&lt;/p&gt;

&lt;p&gt;We haven't covered everything here, but research this for a bit and see what you can find.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;40&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resultVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;variable1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;variable2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resultVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-3/challenge-3-solution.md"&gt;Solution found here.&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Challenge 4
&lt;/h4&gt;

&lt;p&gt;Why is this code invalid?  Edit this until it is valid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objectVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;property1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;i am property 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;property2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;i am property 2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;property3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;objectVariable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;property3&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-3/challenge-4-solution.md"&gt;Solution found here&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Challenge 5
&lt;/h4&gt;

&lt;p&gt;Why does this code not work?  Edit until it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/code-challenges/lesson-3/challenge-5-solution.md"&gt;Solution found here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Lesson 2: What is JavaScript and How is it Used? #fullstackroadmap</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Thu, 17 Dec 2020 23:51:31 +0000</pubDate>
      <link>https://dev.to/zachgoll/fullstack-developer-series-lesson-2-what-is-javascript-and-how-is-it-used-3g81</link>
      <guid>https://dev.to/zachgoll/fullstack-developer-series-lesson-2-what-is-javascript-and-how-is-it-used-3g81</guid>
      <description>&lt;h2&gt;
  
  
  I'm on YouTube
&lt;/h2&gt;

&lt;p&gt;If you get tired of reading...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=q9BdH-oluJY"&gt;Here is the YouTube version&lt;/a&gt; of this lesson.&lt;/p&gt;

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

&lt;p&gt;This is part of my full-stack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first full-stack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please share this series with the hashtag &lt;strong&gt;#fullstackroadmap&lt;/strong&gt; and help me spread the word!&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back.  This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/zg_dev"&gt;My Twitter Profile&lt;/a&gt; - Where you can stay updated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to read this lesson
&lt;/h2&gt;

&lt;p&gt;Unlike many of the posts I write, this one is going to be in the form of a detailed Q&amp;amp;A session. I have put the easier questions at the beginning and the harder ones at the end for the dedicated students out there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the point of this lesson?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Context.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In just a few lessons, we will be talking about variables, data types, functions, loops, and much more, so it is important to get the 10,000 foot view of JavaScript before diving into those details.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is JavaScript?
&lt;/h2&gt;

&lt;p&gt;JavaScript is a programming language. It is unique to other languages like C++, Python, PHP, and others because it is the only language that can run in web browsers (although &lt;a href="https://www.youtube.com/watch?v=cbB3QEwWMlA"&gt;WASM&lt;/a&gt; will change that in the future, but no need to worry about it now).&lt;/p&gt;

&lt;p&gt;More specifically, JavaScript is&lt;/p&gt;

&lt;p&gt;What is a programming language? Well... That's a bit of a loaded question, so I've saved it for the end of this lesson (scroll down).&lt;/p&gt;

&lt;h2&gt;
  
  
  What can you do with JavaScript?
&lt;/h2&gt;

&lt;p&gt;If you asked this 20 years ago, you might have been laughed at. Since then, JavaScript has become capable of building complex web applications like Facebook. Here are some other things you can do with JavaScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run complex &lt;strong&gt;machine learning&lt;/strong&gt; models with &lt;a href="https://www.tensorflow.org/js"&gt;TensorFlow.js&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Build &lt;strong&gt;Desktop applications&lt;/strong&gt; like Visual Studio Code (the code editor I am writing this post in right now) with the &lt;a href="https://www.electronjs.org/"&gt;Electron framework&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Build complex, high-performing &lt;strong&gt;web apps&lt;/strong&gt; like YouTube, Facebook, and Reddit using front-end frameworks like &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt;, &lt;a href="https://angular.io/"&gt;Angular&lt;/a&gt;, or &lt;a href="https://vuejs.org/"&gt;Vue&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Convert your web apps into &lt;strong&gt;Mobile apps&lt;/strong&gt; without changing your code using frameworks like &lt;a href="https://reactnative.dev/"&gt;ReactNative&lt;/a&gt; for React apps and &lt;a href="https://nativescript.org/"&gt;NativeScript&lt;/a&gt; for Angular and Vue apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Speaking of frameworks...&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a JavaScript Framework?
&lt;/h3&gt;

&lt;p&gt;A "framework" is nothing more than an abstraction on top of a specific language. In JavaScript, you'll most commonly see front-end development frameworks like React, Angular, and Vue, but frameworks come in all shapes and sizes. There are also back-end frameworks for JavaScript like ExpressJS, or even more abstracted and advanced–NestJS.&lt;/p&gt;

&lt;p&gt;When thinking about frameworks, just remember that the goal of a framework is to &lt;strong&gt;enable&lt;/strong&gt; the developer to accomplish something in less time.&lt;/p&gt;

&lt;p&gt;You &lt;em&gt;could&lt;/em&gt; create Facebook without a framework, but it would take infinitely longer to do, and would be infinitely harder to maintain over the years. Not to mention, smart developers working at Facebook would inevitably get frustrated with how tedious their work was and create a framework to fix it (cough cough, that's how React was built, which is the framework Facebook currently uses).&lt;/p&gt;

&lt;p&gt;So in summary, all of these things that we can do with JavaScript these days are &lt;strong&gt;enabled&lt;/strong&gt; by frameworks that have been built over the years.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is JavaScript similar to Java?
&lt;/h2&gt;

&lt;p&gt;You'll read it all over the internet. Java is to JavaScript as car is to carpet.&lt;/p&gt;

&lt;p&gt;While JavaScript was &lt;em&gt;inspired by&lt;/em&gt; Java and was originally meant to be a "companion" to Java, the two languages are VERY different.&lt;/p&gt;

&lt;p&gt;Here's some Java code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's some JavaScript code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These programs do the same thing, but are very different looking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is JavaScript better than Python?
&lt;/h2&gt;

&lt;p&gt;The answer to this question is "it depends", which is the answer I would give to any similar question comparing two languages.&lt;/p&gt;

&lt;p&gt;If you want to build a complex web app and hire people to work on it and maintain it, I would argue that JavaScript is a better language to write it in. Does this mean that JavaScript performs better? Not necessarily. Does this mean JavaScript is easier to understand? Ehh, Python is WAY easier. The reason I say this is because JavaScript has a large web development ecosystem built around it that Python is slightly lacking in. In other words, the &lt;strong&gt;tools&lt;/strong&gt; required for the job are more mature in the JS web dev ecosystem than the Python web dev ecosystem. You certainly could build a web app using Python (although you still need JavaScript for the front-end), but I would generally not recommend it.&lt;/p&gt;

&lt;p&gt;But what if I wanted to build an image recognition API that uses machine learning to grant security access to employees walking into a building? I'd probably go with Python here. The Data Science and Machine Learning ecosystem is primarily centered around the Python programming language and various Python frameworks like Scikit-Learn, Tensorflow, and PyTorch. You &lt;em&gt;could&lt;/em&gt; build machine learning apps with JavaScript using TensorflowJS, but overall, the Python communities online (currently) have more collective resources and knowledge about Machine Learning than the JavaScript communities do (although this certainly could evolve and change).&lt;/p&gt;

&lt;h2&gt;
  
  
  Is JavaScript the same as ECMAScript?
&lt;/h2&gt;

&lt;p&gt;Nope, JavaScript is an &lt;em&gt;implementation&lt;/em&gt; of an ECMAScript &lt;em&gt;standard&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This will be easier to discuss with some context&lt;/strong&gt;, so let's look at a couple examples of "Standards Organizations".&lt;/p&gt;

&lt;p&gt;Ever seen a date 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;2020-12-15T15:17:19.417Z
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an &lt;code&gt;ISO-8601&lt;/code&gt; formatted datetime represented in UTC time.&lt;/p&gt;

&lt;p&gt;The previous sentence has &lt;strong&gt;two&lt;/strong&gt; standards involved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, we have the &lt;code&gt;ISO-8601&lt;/code&gt; standard as described by an organization called the &lt;a href="https://www.iso.org/home.html"&gt;International Organization for Standardization&lt;/a&gt;, and is a "standardized" way to &lt;em&gt;format&lt;/em&gt; a datetime. You can even see this implemented in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myDateISO8601&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toISOSTring&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myDateISO8601&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use what you learned in &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/1-first-program/"&gt;the prior lesson&lt;/a&gt; of this series to run this program in the dev tools console!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, I mentioned that this date was in "UTC" time, which is a timezone described by a standards organization called the &lt;a href="https://www.itu.int/en/Pages/default.aspx"&gt;International Telecommunications Union&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does this have anything to do with ECMAScript?
&lt;/h3&gt;

&lt;p&gt;Organizations like the ones mentioned above are &lt;strong&gt;similar to&lt;/strong&gt; the &lt;a href="https://www.ecma-international.org/"&gt;ECMA International&lt;/a&gt; organization which defines the standards for "ECMAScript" programming languages.&lt;/p&gt;

&lt;p&gt;Just like an ISO-8601 date is a standard implemented by various programming languages and computers, ECMAScript is a standard implemented by JavaScript (and a few other less popular programming languages like ActionScript and JScript).&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do we need a standard like ECMAScript?
&lt;/h3&gt;

&lt;p&gt;When I first started learning web development, I had no idea how many standards organizations existed. But why do we have them?&lt;/p&gt;

&lt;p&gt;In the case of ECMAScript, this standard is important primarily for &lt;strong&gt;browser compatibility&lt;/strong&gt;. Remember, a web browser is just another computer application, and thus, must be programmed to support various features in JavaScript. The JavaScript language is constantly evolving, and in order for all the browser developers to stay on the same page and make sure that their browser will support these new features, there needs to be a centralized standard to follow.&lt;/p&gt;

&lt;p&gt;If ECMAScript did not exist, it would be near impossible for all the different browsers (Chrome, Firefox, Safari, Edge, Brave, and last but very least, Internet Explorer) to stay compatible with new JavaScript features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can Learning JavaScript Get You a Job?
&lt;/h2&gt;

&lt;p&gt;If you've read the prior questions, you can probably guess that &lt;strong&gt;YES, JavaScript is a very employable coding language.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That said, knowing &lt;strong&gt;JavaScript alone will not get you there.&lt;/strong&gt; You need to learn various JavaScript frameworks like React and Angular used at top companies like Facebook and Google respectively.&lt;/p&gt;

&lt;p&gt;Heck, JavaScript is actually the most widely used programming language as of 2020 &lt;a href="https://insights.stackoverflow.com/survey/2020#most-popular-technologies"&gt;according to StackOverflow.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Is HTML and CSS Required to Write Javascript?
&lt;/h2&gt;

&lt;p&gt;Yes and no. It depends on &lt;em&gt;where&lt;/em&gt; you are writing the JavaScript (which we will talk about later in this post).&lt;/p&gt;

&lt;h3&gt;
  
  
  In the Browser
&lt;/h3&gt;

&lt;p&gt;The purpose of JavaScript run in the browser is to &lt;strong&gt;modify HTML and CSS&lt;/strong&gt; via the DOM (Document Object Model). Again, we haven't talked about the DOM yet, but will get there soon in this series.&lt;/p&gt;

&lt;p&gt;For example, let's say you have a button in your web app that allows you to save your profile image and return to the main screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fazhdssbigdbbpn62zz6o.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fazhdssbigdbbpn62zz6o.JPG" alt="save button" width="519" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is what this button would look like &lt;em&gt;without&lt;/em&gt; CSS and &lt;em&gt;without&lt;/em&gt; JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzb2pdg8fude5nyecgeya.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzb2pdg8fude5nyecgeya.JPG" alt="button without style" width="200" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is what this button would look like &lt;em&gt;with&lt;/em&gt; CSS, but &lt;em&gt;without&lt;/em&gt; JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5dgp8exwewcfiu6n7sma.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5dgp8exwewcfiu6n7sma.JPG" alt="button with styling" width="201" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait a second... Isn't that the same as the original screenshot? Yes, it is. And that is because JavaScript has nothing to do with the look and feel of a website, but rather the "brains" of the website. If I created this button with just HTML and CSS, when the user clicks the button, their profile &lt;strong&gt;will not save&lt;/strong&gt;. And this is where JavaScript comes to the rescue.&lt;/p&gt;

&lt;p&gt;My app has JavaScript written that will listen for a user's click, and once clicked, will grab all the data from the profile page and send it as an API request to the back-end server, which will update the profile data in the database.&lt;/p&gt;

&lt;p&gt;As you can see, when talking about JavaScript in the web browser, it must &lt;strong&gt;work together&lt;/strong&gt; with HTML and CSS to create a functional user experience. Without HTML, you have nothing on your web page. Without CSS, you have an ugly web app. And without JavaScript, you have a webpage that is 100% static (i.e. you can't interact with it).&lt;/p&gt;

&lt;h3&gt;
  
  
  In NodeJS
&lt;/h3&gt;

&lt;p&gt;If you are writing JavaScript on the &lt;a href="https://www.zachgollwitzer.com/posts/2020/frontend-backend-fullstack/"&gt;back-end&lt;/a&gt;, HTML and CSS are not required.&lt;/p&gt;

&lt;p&gt;Rather than playing nicely with its friends, HTML and CSS, back-end JavaScript will be hanging out with the database, various JS libraries, and APIs. Once again, more on this later in the series.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a programming language?
&lt;/h2&gt;

&lt;p&gt;At the beginning of this post, I mentioned that JavaScript is a programming language, but spared you the details until now. If you want to stop reading here, that is fine, but I strongly believe that as a programmer, understanding the following concepts at least at a high-level is important in your full-stack web development career.&lt;/p&gt;

&lt;p&gt;I'm generalizing a LOT here, but a programming language is a group of symbols (often called "tokens") that when combined together in a VERY specific way, can be translated into the 1s and 0s that a computer is able to run.&lt;/p&gt;

&lt;p&gt;Think about it like this–we have many different spoken languages, and not all languages make sense to all people. If you started speaking Portuguese to me, my brain would simply not be able to process the various words/phrases/symbols that come with this unique language. But if you spoke English to me, my brain is very familiar with the "rules" required to translate all the words/phrases/symbols.&lt;/p&gt;

&lt;p&gt;But there is one thing that is common among all people–&lt;strong&gt;body language&lt;/strong&gt;. No matter what country you are from, although I cannot speak your language, I can certainly tell whether you are in distress, whether you are happy, or whether you are excited.&lt;/p&gt;

&lt;p&gt;Bring it back to computers now. Every computer has a common language (i.e. "body language"), and that is 1s and 0s (synonymous with "binary" or "machine code").&lt;/p&gt;

&lt;p&gt;Computers can't speak JavaScript. Computers can't speak Python. Computers can't speak C++. But if we write a program called a "compiler" to convert those symbols to 1s and 0s, we can translate each of these languages into the "body language" (i.e. 1s and 0s) that all computers can understand.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The remainder of this section is optional reading. To me, it is extremely interesting, but if you are trying to learn web development quickly and get a job ASAP, I suggest avoiding the rabbit hole that the next paragraph will take you down.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My explanation here is extremely simplified, and there are obviously a lot more steps and nuances involved in the process of converting a language like JavaScript into the 1s and 0s that the computer can read. To fully cover this subject, we would have to get into a discussion about syntax analysis (part 1 of the compilation process which includes lexical analysis, parse trees, recursive descent algorithms, etc.) and code generation (part 2 of the compilation process which deals with symbol tables and other fun stuff). Writing a compiler also depends on your target platform; whether you're writing it for a virtual machine or a specific CPU spec. And finally, you have to talk about the process of how all this happens. Does the code get compiled dynamically like JavaScript? Or does it get compiled manually like C, Go, or Rust? If it is compiled "on the fly" like JavaScript, how can we optimize this process to be almost as fast as manual compilation (hint: JIT compilation).&lt;/p&gt;

&lt;p&gt;If the prior paragraph interested you despite you not understanding it one bit, I suggest two resources.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If you want a hands-on and practical understanding of how code is parsed and compiled (I'm talking SUPER detailed stuff here), check out the book &lt;a href="https://geni.us/eocs"&gt;Elements of Computing Systems&lt;/a&gt;. You have been warned, this will be a LARGE detour from your full-stack web dev journey, but I personally went on this detour and while it delayed my web dev journey, I came out of it with some serious knowledge that I was pretty pumped about.&lt;/li&gt;
&lt;li&gt;If you are interested in these low-level topics, but don't care to get your hands dirty and see them in action, I recommend reading the book &lt;a href="https://geni.us/code-sb"&gt;Code by Charles Petzold&lt;/a&gt;. This is no easy read, but will not be as large of a detour as the first option here.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Where does JavaScript code run? (optional)
&lt;/h2&gt;

&lt;p&gt;When we talk about where a programming language runs, we call it a "runtime". JavaScript has two primary "runtimes":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the browser&lt;/li&gt;
&lt;li&gt;In NodeJS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Again, this gets into the topic of compilers (mentioned in the previous section), so I will keep it brief and high-level.&lt;/p&gt;

&lt;p&gt;You know how I mentioned in the previous section that every coding language has a different compiler written for it? Well this is where that comes into play. When running JavaScript in the Google Chrome browser, we need something that will translate that code into machine languages (1s and 0s) that our computer (which runs the browser) can execute. To do this, Chrome uses something called the &lt;a href="https://en.wikipedia.org/wiki/V8_(JavaScript_engine)"&gt;V8 Engine&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since we are using Firefox for this full-stack series, I'll mention that unlike Google Chrome, Firefox uses a different JavaScript Engine called SpiderMonkey, which was actually the original JavaScript engine used back in the days of the NetScape browser (side note - if you want an entertaining podcast to listen to, check out &lt;a href="https://www.stitcher.com/show/business-wars/episode/browser-wars-kickstarting-a-revolution-1-57422435"&gt;Browser Wars&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;And for NodeJS? Well, this is a slightly different runtime because it allows JavaScript to run completely separate from a web browser. Nevertheless, NodeJS actually uses the V8 Engine just like Google Chrome does to compile and run JavaScript. NodeJS is written in C++ and leverages the V8 Engine internally. As you might guess, the maintainers of the NodeJS project and the V8 Engine project have become close colleagues over the years considering how popular NodeJS has become.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;You are officially two lessons down in the full-stack roadmap series, and we still haven't learned how to write JavaScript. Bummer.&lt;/p&gt;

&lt;p&gt;But... I promise you, the context you are getting in these first couple lessons will help you tremendously along the way, so stick with it!&lt;/p&gt;

&lt;p&gt;Be sure to &lt;a href="https://lists.zachgollwitzer.com/"&gt;get on my email list&lt;/a&gt; to receive updates when I post lessons in the future!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Lesson 1: Your First JavaScript Program (Fullstack developer roadmap series)</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Mon, 14 Dec 2020 01:15:25 +0000</pubDate>
      <link>https://dev.to/zachgoll/fullstack-developer-series-lesson-1-your-first-javascript-program-d98</link>
      <guid>https://dev.to/zachgoll/fullstack-developer-series-lesson-1-your-first-javascript-program-d98</guid>
      <description>&lt;h2&gt;
  
  
  I'm on YouTube
&lt;/h2&gt;

&lt;p&gt;If you get tired of reading...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=XWS5w5eQzFk&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq&amp;amp;index=2"&gt;Here is the YouTube version&lt;/a&gt; of this lesson.&lt;/p&gt;

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

&lt;p&gt;This is part of my full-stack developer series, where &lt;strong&gt;you'll go from never having written a line of code to deploying your first full-stack web application to the internet.&lt;/strong&gt; &lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Click this link&lt;/a&gt; to get an overview of what this series is all about.&lt;/p&gt;

&lt;p&gt;Please share this series with the hashtag &lt;strong&gt;#fullstackroadmap&lt;/strong&gt; and help me spread the word!&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful series links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/fullstack-roadmap-toc"&gt;Series Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;Github Repository&lt;/a&gt; - where you'll find all the code we write in this series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZZJT5uskuvI&amp;amp;list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube Playlist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Series Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.100daysofcode.com/"&gt;100 Days of Code Challenge&lt;/a&gt; - I highly recommend you take this on while reading this series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codewars.com/users/zachgoll"&gt;My CodeWars Profile&lt;/a&gt; - Follow me and I'll follow you back.  This is where we will do our coding challenges throughout the series!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/zg_dev"&gt;My Twitter Profile&lt;/a&gt; - Where you can stay updated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where do we start?
&lt;/h2&gt;

&lt;p&gt;If you're reading this, you've most likely never written a line of code in your life, but want to learn. There are about a hundred different ways that we could get you on your feet and get started, but I think one of the best ways to get started is by seeing what's possible with very minimal effort.&lt;/p&gt;

&lt;p&gt;As with anything new, you will have a million questions floating through your head. &lt;strong&gt;If you feel lost as we go through this, that's okay. You should.&lt;/strong&gt; But trust me when I say that I got you--while things may not seem connected early on, I'll bring this stuff full circle for you and hopefully turn you into a full-stack web developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser Devtools
&lt;/h2&gt;

&lt;p&gt;We start our journey in a place that you have probably been close to, but have never seen. If you're a Stranger Things fan, &lt;strong&gt;we're about to enter&lt;/strong&gt; &lt;a href="https://youtu.be/Np5KfdMSsXg?t=63"&gt;the world of the "upside-down"&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To start, you will need to &lt;a href="https://www.mozilla.org/en-US/firefox/"&gt;download the Firefox web browser&lt;/a&gt; to your computer. For the sake of this tutorial, it is best that we are all looking at the same thing.&lt;/p&gt;

&lt;p&gt;Why Firefox?&lt;/p&gt;

&lt;p&gt;This tutorial will work in any web browser (they all have their own developer tools), but we are using Firefox because their Dev tools are arguably the easiest to navigate and most helpful to beginners. And speaking of Dev tools... What are those anyway?&lt;/p&gt;

&lt;p&gt;Glad you asked. You are going to get really familiar with these "dev tools" over the next several months because they are built-in tools included with any web browser that allows developers to see what is going on behind the scenes with their web applications; hence &lt;strong&gt;dev&lt;/strong&gt; (developer) tools. To get to them, right-click anywhere in your browser and select the "Inspect" option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/Ll548y4RBL7WEBXjHQ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Ll548y4RBL7WEBXjHQ/giphy.gif" alt="opening dev tools" width="480" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this view, there is a lot going on. Before we write our first program, I want to introduce some of the high-level things that these developer tools can help us do.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspector
&lt;/h3&gt;

&lt;p&gt;The inspector (the default view from the GIF above) is probably the most frequented area of these tools for most developers. This is where you will inspect the HTML and CSS (don't worry, we will learn this eventually) displayed on the webpage. You can also make changes to the HTML and CSS to see what your webpage would look like before you actually make the change in your code. In other words, &lt;strong&gt;any changes you make in dev tools will NOT affect your actual webpage; they are temporary&lt;/strong&gt;. Because we are making temporary edits, you can actually change the look and feel of ANY website; even if you can't edit the code behind it. But remember, nobody else will see this because it is a local, temporary change that will be overwritten on your next browser refresh.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/fsNw4oTUXT3mkzYYyO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fsNw4oTUXT3mkzYYyO/giphy.gif" alt="devtools demo" width="480" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we get to the lessons on the Document Object Model (DOM) and the Box Model in our HTML and CSS section of the series, you will learn a lot more about this area of dev tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Console
&lt;/h3&gt;

&lt;p&gt;You'll also spend a large amount of your time working in the console. The console is actually called a "REPL", which means read, evaluate, print, loop. Don't worry too much about this definition now. Instead, just remember that the console is primarily good for two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allows you to write JavaScript code&lt;/li&gt;
&lt;li&gt;Allows you to modify the DOM (Document Object Model), which we haven't covered yet, but will get to.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is an example of me demonstrating both of these ideas in the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/6ZyaQA3BKMRs0izhcv/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/6ZyaQA3BKMRs0izhcv/giphy.gif" alt="console" width="480" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, there is a lot that we can do in the console, and &lt;strong&gt;we will be spending a lot of time here for the next several lessons&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Network
&lt;/h3&gt;

&lt;p&gt;As a web developer, you will use the network tab quite frequently, but we will not get into the details of it for quite some time here. The network tab allows you to see the "resources" that are being transferred over the network and loaded in your webpage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/5f9Bp5eAWdqLEDMaLe/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/5f9Bp5eAWdqLEDMaLe/giphy.gif" alt="network" width="480" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, if I wanted to see how long it took the webpage to load the main image, what cookies got set when it was loaded, or even how large the image was, I could go to the Network tab (shown above), select "Images", and then click on the image in question.&lt;/p&gt;

&lt;p&gt;Again, don't worry about this too much now, but know that we will be working with this later in the series.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storage
&lt;/h3&gt;

&lt;p&gt;The storage tool is yet another common thing you'll be using as a web developer, but like the network tab, we will not get to it for some time. This is also called the "Application" tab if you are using Google Chrome Dev Tools.&lt;/p&gt;

&lt;p&gt;While most data on a web page is stored in a database and then retrieved via API calls, some data can actually be stored within the user's browser for later retrieval. When you visit websites and are asked to accept the Cookie agreement, this is what they are referring to.&lt;/p&gt;

&lt;p&gt;Every browser like Firefox has the capability of storing web cookies and other data, which is useful for tracking user behavior (cough, Facebook), authentication, and several other things.&lt;/p&gt;

&lt;p&gt;Like the Network tab, don't worry about this for now. Nevertheless, here is a quick view of me inspecting the cookies that Google has set in my browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/sIxxD5ZcXl2sC9v8Pi/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/sIxxD5ZcXl2sC9v8Pi/giphy.gif" alt="storage" width="480" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most of the time, the values stored here won't mean much to you if you're looking from the outside-in. But if you are actually developing a web app, this area can become very useful as we will see later.&lt;/p&gt;

&lt;h3&gt;
  
  
  All Other Dev Tools
&lt;/h3&gt;

&lt;p&gt;You will see several other tools such as the debugger, style editor, performance, and accessibility, but I am leaving them off here because you won't need them starting out, and quite honestly, you may never use them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your First JavaScript Program
&lt;/h2&gt;

&lt;p&gt;If you are reading this, you probably haven't written a lot of code in your life. I don't want to turn this series into a book, but rather an interactive, results-based course. For that reason, even if you don't understand the code we are about to write, I want to get you a quick win here and show you what it is like to write code.&lt;/p&gt;

&lt;p&gt;While you can copy and paste the code snippets, I suggest typing them in line by line to get a feel for the console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this JS program, we will be changing the background of Google's homepage every time we click the screen.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is what it looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This is a JavaScript comment.  It doesn't affect the code at all&lt;/span&gt;

&lt;span class="c1"&gt;// Here, we are selecting the &amp;lt;body&amp;gt;&amp;lt;/body&amp;gt; HTML tag&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;htmlBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// This is a function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomClickFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// This is an array of color codes.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#002942&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#0CA7DB&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#F56C05&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#DB3E00&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="c1"&gt;// This will calculate a random "index" that we can use to select a color in the array&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// We are selecting a single value from our "colors" array above&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;randomIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="c1"&gt;// We are setting the webpage background our random color&lt;/span&gt;
  &lt;span class="nx"&gt;htmlBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomColor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// We are printing a message to the console&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The user clicked and turned the background&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;randomColor&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// This sets an "event listener" which "listens" for click events on the webpage&lt;/span&gt;
&lt;span class="nx"&gt;htmlBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onclick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomClickFunction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is what it does.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/jMeP87xwdLbQv91WZF/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/jMeP87xwdLbQv91WZF/giphy.gif" alt="your first js program" width="480" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A few comments on this program
&lt;/h3&gt;

&lt;p&gt;To wrap it up for this lesson, I want to point out some things about what we just did. I'm not going to be explaining every detail of how this program works because we will be diving into the JavaScript programming language in detail over the next several lessons in the series.&lt;/p&gt;

&lt;p&gt;The purpose of writing this program was to demonstrate how you can run real code without installing fancy software or writing commands on the command line.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be sure to read through the comments that I placed in the code above. Everything we write after the &lt;code&gt;//&lt;/code&gt; character is considered a comment in JavaScript. The commenting syntax will differ between languages. For example, to make a comment in the Python programming language, you would use &lt;code&gt;#&lt;/code&gt; rather than &lt;code&gt;//&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Notice how in my &lt;code&gt;colors&lt;/code&gt; variable, I have several "hex codes", but I can also specify a plaintext color such as "purple". These are all valid CSS values (more to come later).&lt;/li&gt;
&lt;li&gt;I would consider this code to be at the intermediate level of difficulty. It took me several months of writing code before I could write something like this on my own, so don't worry if it doesn't make any sense!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Where you write the code matters!
&lt;/h3&gt;

&lt;p&gt;There is a very good reason why we are using the Firefox developer tools, and specifically, the console. In order to run JavaScript code, you need to have a tool that "compiles" the JavaScript programming language. This compiler will look at the code that we wrote above and convert it to the 1s and 0s that the computer you are working at can read and understand.&lt;/p&gt;

&lt;p&gt;We may touch on some of these low-level details such as "compilation" throughout the series, but when talking about 1s and 0s, we are dipping into the realm of Computer Science, which is very different from web development. Computer Science is what &lt;em&gt;enables&lt;/em&gt; web development, but not every computer scientist will know how to develop on the web. You don't need to be an accomplished chef to work at Chipotle, but without the work of talented chefs, there would be no Chipotle in existence.&lt;/p&gt;

&lt;p&gt;We could have written this code in a code/text editor, but this would have required us to perform several additional steps to get the code compiled and running smoothly in the browser. By using the Firefox console, we are able to write JavaScript code &lt;strong&gt;without any setup&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Writing code in the Firefox browser console is easy for starters, but a very inefficient place to write large amounts of code. Eventually, we will move away from this in favor of a more efficient code editor, but this is a great place to learn the basics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;This concludes lesson #1 of the full-stack developer series.&lt;/p&gt;

&lt;p&gt;Be sure to &lt;a href="https://lists.zachgollwitzer.com/"&gt;get on my email list&lt;/a&gt; to receive updates when I post lessons in the future!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/introduction/"&gt;Go to prior lesson&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/zachgoll/fullstack-developer-series-lesson-2-what-is-javascript-and-how-is-it-used-3g81"&gt;Go to next lesson&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Optional Challenge
&lt;/h3&gt;

&lt;p&gt;If you're looking for a way to practice what we've learned, here's your challenge:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random"&gt;only this page&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Console/log"&gt;this page&lt;/a&gt;, see if you can figure out how to print a random number between 0-100 to the console in the Firefox developer tools&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Fullstack Developer Series - Learn to Code in 2021 and Beyond</title>
      <dc:creator>Zach Gollwitzer</dc:creator>
      <pubDate>Mon, 14 Dec 2020 01:12:10 +0000</pubDate>
      <link>https://dev.to/zachgoll/fullstack-developer-series-learn-to-code-in-2021-and-beyond-38l1</link>
      <guid>https://dev.to/zachgoll/fullstack-developer-series-learn-to-code-in-2021-and-beyond-38l1</guid>
      <description>&lt;p&gt;Welcome to my free series on learning to code. Through this free series, you will go from zero experience to deploying your first full-stack web application. Along the way, I'll teach you the essential web development concepts needed for 2021 and beyond.&lt;/p&gt;

&lt;p&gt;Please share this series with the hashtag #fullstackroadmap and help me spread the word!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we building?
&lt;/h2&gt;

&lt;p&gt;Update (3/23/21): When I first created this series, I said that we were going to create a personal blog and content management system, but then I realized how boring that is.  Instead, &lt;strong&gt;we will be building an E-Commerce application with Stripe integration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By the end of this course, you will have a fully functioning app that you can sell real products on.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No, it won't be as good as Shopify or WooCommerce.  There is a reason these solutions dominate the market–they have a team of developers and have been improved upon for years.&lt;/p&gt;

&lt;p&gt;While our solution won't be world-changing, building an E-Commerce website is one of the best ways to learn all the concepts of full-stack web development AND it will be good enough for you to sell your own products or courses if that's something you're interested in!&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I will be updating this course
&lt;/h2&gt;

&lt;p&gt;All updates to this series will be made on &lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/blob/main/README.md"&gt;my Github repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you don't have an account on &lt;a href="https://github.com/join"&gt;Github, create one now&lt;/a&gt;. You need to do this to follow along with this series, but this will also be the account that employers will look at when you are interviewing for jobs (so make sure your username is professional).&lt;/p&gt;

&lt;p&gt;Once you have created your account, go to &lt;a href="https://github.com/zachgoll/fullstack-roadmap-series"&gt;my series repository&lt;/a&gt; and click the star so that you can find it easily later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fde0n6zea3w6e7kqn6ldy.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fde0n6zea3w6e7kqn6ldy.JPG" alt="github star" width="443" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is this for?
&lt;/h2&gt;

&lt;p&gt;This series is perfect for you if...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have &lt;strong&gt;never written a line of code&lt;/strong&gt; in your life, but want to learn what coding is all about&lt;/li&gt;
&lt;li&gt;You are just starting your journey to becoming a full-stack JavaScript developer but &lt;strong&gt;need a roadmap to guide you&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;You have some experience with front or back-end web development but need to brush up on your skills&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You might ask, how could this series be for all of these varying skillsets?&lt;/p&gt;

&lt;p&gt;Well, my intention with the series is to go in sequential order from the most beginner topics to even some advanced web development topics, which means &lt;strong&gt;you can jump into the series according to where you are at in your personal journey!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What skills will I have at the end?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's be very clear. This series will teach you how to code and will teach you the discipline of web development&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In other words, by the end of the series, you will know how to code in JavaScript, and you will know how to create &lt;strong&gt;web&lt;/strong&gt; (not mobile) applications such as &lt;a href="https://www.facebook.com/"&gt;Facebook&lt;/a&gt;, &lt;a href="https://www.youtube.com/"&gt;YouTube&lt;/a&gt;, &lt;a href="https://quickbooks.intuit.com/"&gt;Quickbooks&lt;/a&gt;, &lt;a href="https://www.youneedabudget.com/"&gt;You Need a Budget&lt;/a&gt;, or even my own app, &lt;a href="https://training.thediygolfer.com/"&gt;Eagle Eye Golf Performance&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since this series will teach you how to code (which is very transferable to other disciplines), here are the disciplines that &lt;strong&gt;we will NOT cover in this series&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to code IOS or Android apps&lt;/li&gt;
&lt;li&gt;Data science, AI, and Machine Learning&lt;/li&gt;
&lt;li&gt;Advanced DevOps (we will cover the basics though)&lt;/li&gt;
&lt;li&gt;How to code in languages other than JavaScript (although we will explore a few others to give you some exposure throughout the course)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What topics will I learn in this series?
&lt;/h2&gt;

&lt;p&gt;In this series, you will learn the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to code (we will use JavaScript, and here's why)&lt;/li&gt;
&lt;li&gt;General web development concepts (not specific to any language or framework)&lt;/li&gt;
&lt;li&gt;Exposure to various web frameworks without diving too deep into any&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A detailed outline can be found at the bottom of this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can I ask questions?
&lt;/h2&gt;

&lt;p&gt;While I may not be able to respond immediately, &lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/issues/new?assignees=zachgoll&amp;amp;labels=question&amp;amp;template=course-related-question.md&amp;amp;title=Please+provide+a+descriptive+title+of+your+question"&gt;please follow this template on my Github repository&lt;/a&gt; to raise your questions. You will need a Github account to do this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are you excluding certain technologies here?
&lt;/h2&gt;

&lt;p&gt;When I first learned to code, I read through &lt;a href="https://roadmap.sh/frontend"&gt;roadmaps like this one&lt;/a&gt; which are great, but extremely intimidating. Not only that, but in hindsight, I know that these roadmaps are unrealistic for someone starting out. I've been coding almost every day for over 4 years, and I haven't even covered all the topics you might find in these roadmaps. They are great for seeing the landscape ahead, but not so great for getting yourself started.&lt;/p&gt;

&lt;p&gt;Because of this, I have chosen specific technologies for you to learn throughout this series that I think will make you the most versatile (and hireable) developer possible. We won't cover everything out there, but we will learn modern technologies that real companies use.&lt;/p&gt;

&lt;p&gt;For example, when we get to the part of the course where we learn about web hosting for our app, there are TONS of options. We could use AWS, Azure, Linode, Digital Ocean, Heroku, and many more. But in this series, we will be using Digital Ocean because it is cheap, has a simple interface, and will teach you the first principles of hosting a web app that can be applied to any other hosting company. Aka, you'll be learning versatile skills here without having to make a choice yourself.&lt;/p&gt;

&lt;p&gt;After going through this series, you will explore MANY MANY more technologies, so don't worry about covering them all now. Right now, the goal is to learn web development, and &lt;strong&gt;analysis paralysis of "what tool should I use?" shouldn't get in the way of that.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Q&amp;amp;A
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Where can I take this course?
&lt;/h3&gt;

&lt;p&gt;I will be posting on my blog, Dev, Medium, and YouTube. Below are the relevant links to find the series.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.zachgollwitzer.com/"&gt;My blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/zachgoll"&gt;Dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://zach-gollwitzer.medium.com/"&gt;Medium&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLYQSCk-qyTW37zDPzcAyzCsnypFQrhUcq"&gt;YouTube&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why I chose JavaScript
&lt;/h3&gt;

&lt;p&gt;It's nearly 2021, and according to the StackOverflow developer survey, &lt;a href="https://insights.stackoverflow.com/survey/2020#technology-programming-scripting-and-markup-languages"&gt;JavaScript is the most widely used programming language&lt;/a&gt; AND happens to be the language I'm most proficient in. Here are some additional reasons why JavaScript is a good choice for us.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript powers the web, and will for years into the future&lt;/li&gt;
&lt;li&gt;JavaScript can be used on both the front-end and the back-end (more on this &lt;a href="https://www.zachgollwitzer.com/posts/frontend-backend-fullstack/"&gt;here&lt;/a&gt;). This is important because we only have to learn one language to build full-stack web applications rather than two.&lt;/li&gt;
&lt;li&gt;JavaScript is the only true programming language that can be used in the browser, so you pretty much have to learn it no matter what (there is a nuance here though--with the introduction of &lt;a href="https://www.youtube.com/watch?v=cbB3QEwWMlA"&gt;WASM&lt;/a&gt;, you will be able to write non-JavaScript languages in the browser, but this is in its infancy and not something you will be learning at the beginning of your journey)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why is this free?
&lt;/h3&gt;

&lt;p&gt;I'll be honest, this is free because I don't have the time (I work a full-time job and do this on the side) to sit down and craft together a complete training course from start to finish, record it, edit it, market it, and market it some more. That said, my intention is to provide as good, if not a better quality series for free than most paid training courses. I do plan to sell courses in the future, but I am very passionate about teaching this subject and think everyone should have the opportunity to learn to code for free.&lt;/p&gt;

&lt;p&gt;I genuinely think that if you go through this series, you will have the required skills to get a job as a full-stack JavaScript web developer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Detailed Series Outline
&lt;/h3&gt;

&lt;p&gt;Please note that &lt;strong&gt;this is an evolving outline&lt;/strong&gt;. If there are essential web development topics that I have missed, please &lt;a href="https://github.com/zachgoll/fullstack-roadmap-series/issues/new?assignees=zachgoll&amp;amp;labels=enhancement&amp;amp;template=content-suggestions.md&amp;amp;title=Enter+a+detailed+content+suggestion+title"&gt;raise an issue on Github&lt;/a&gt; and I will consider adding it.&lt;/p&gt;

&lt;p&gt;Also, please note that the actual series may not follow this outline's sequence, but will cover all of the topics at some point.&lt;/p&gt;

&lt;h4&gt;
  
  
  Part 1: Coding Basics
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Projects
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;30+ JavaScript Code Challenges (mostly on CodeWars)&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Topics
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Write your first JavaScript program&lt;/li&gt;
&lt;li&gt;Introduction to JavaScript (what is it, how it is used, etc.)&lt;/li&gt;
&lt;li&gt;Browser Developer Tools&lt;/li&gt;
&lt;li&gt;How to read Documentation (MDN - Mozilla Developer Network)&lt;/li&gt;
&lt;li&gt;Variables and Data Types&lt;/li&gt;
&lt;li&gt;Operators (arithmetic, comparison, logical, etc.)&lt;/li&gt;
&lt;li&gt;Conditional Statements (if, else-if, switch/case)&lt;/li&gt;
&lt;li&gt;Loops&lt;/li&gt;
&lt;li&gt;Functions (plus intro to "callback" functions)&lt;/li&gt;
&lt;li&gt;Built-in JavaScript Objects

&lt;ul&gt;
&lt;li&gt;String methods&lt;/li&gt;
&lt;li&gt;Array methods&lt;/li&gt;
&lt;li&gt;Regular Expressions&lt;/li&gt;
&lt;li&gt;Math Object&lt;/li&gt;
&lt;li&gt;Date Object&lt;/li&gt;
&lt;li&gt;Error Object (and basic error handling)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Part 2: The Basics of Front-End Development
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Projects
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codepen.io/zg_dev/pen/gOLboGj"&gt;Random Meme/Joke Generator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.frontendmentor.io/challenges/single-price-grid-component-5ce41129d0ff452fec5abbbc"&gt;Pricing Card&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.frontendmentor.io/challenges/testimonials-grid-section-Nnw6J7Un7"&gt;Testimonial Grid&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.frontendmentor.io/challenges/crowdfunding-product-page-7uvcZe7ZR"&gt;Crowdfunding Product Page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Topics
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;HTML Crash Course&lt;/li&gt;
&lt;li&gt;The "DOM" (Document Object Model)&lt;/li&gt;
&lt;li&gt;CSS Crash Course&lt;/li&gt;
&lt;li&gt;CSS Flexbox&lt;/li&gt;
&lt;li&gt;CSS Grid&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Part 3: Basics of Back-End Development
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Projects
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;E-Commerce App API&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Topics
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Terminal Basics&lt;/li&gt;
&lt;li&gt;Git Basics (Version Control)&lt;/li&gt;
&lt;li&gt;NodeJS Crash Course&lt;/li&gt;
&lt;li&gt;Introduction to Package Management with NPM&lt;/li&gt;
&lt;li&gt;Express Crash Course&lt;/li&gt;
&lt;li&gt;Introduction to PostgreSQL Database&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Part 4: E-Commerce App from Scratch (React, PostgreSQL, Express)
&lt;/h4&gt;

&lt;p&gt;This part of the course will be a series of videos that will allow us to apply our skills learned throughout the course to build an E-Commerce application from scratch!&lt;/p&gt;

&lt;h4&gt;
  
  
  Part 5: Deployment, Testing, and CI/CD Workflows
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Introduction to Digital Ocean and VPS (Virtual Private Servers)&lt;/li&gt;
&lt;li&gt;Introduction to Nginx&lt;/li&gt;
&lt;li&gt;Testing your app with Jest&lt;/li&gt;
&lt;li&gt;CI / CD Introduction&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;This concludes the introduction to the full-stack developer series.&lt;/p&gt;

&lt;p&gt;Be sure to &lt;a href="https://lists.zachgollwitzer.com/"&gt;get on my email list&lt;/a&gt; to receive updates when I post lessons in the future!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/1-first-program/"&gt;Go to next lesson&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
