<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jordan Holt</title>
    <description>The latest articles on Forem by Jordan Holt (@jordanholtdev).</description>
    <link>https://forem.com/jordanholtdev</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%2F464202%2F90ec1627-448d-4acb-b2cf-d8af0bac2aea.png</url>
      <title>Forem: Jordan Holt</title>
      <link>https://forem.com/jordanholtdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jordanholtdev"/>
    <language>en</language>
    <item>
      <title>Important Network Concepts for Beginners</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Mon, 30 Aug 2021 04:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/important-network-concepts-for-beginners-2p6h</link>
      <guid>https://forem.com/jordanholtdev/important-network-concepts-for-beginners-2p6h</guid>
      <description>&lt;p&gt;Networks are all around us. What do you see when you picture a network? Do you think of an enormous data center with endless rows of computers and thousands of blinking lights?&lt;/p&gt;

&lt;p&gt;Maybe you think of your cell phone or your tablet, and how you connect to a website? All of those are examples of networks. We have come to rely on networks in our daily life.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fnetwork-city-lights-1024x640.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fnetwork-city-lights-1024x640.jpg" alt="An aerial photo of a city at night. Emphasizing the extent we rely on networks in daily life." width="800" height="400"&gt;&lt;/a&gt;Networks are all around us&lt;/p&gt;

&lt;p&gt;In this article we will learn about computer networks and typical network components.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is a network?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Networks are used to make connections between computers, with the purpose of transmitting data.&lt;/p&gt;

&lt;p&gt;They can consist of just a couple of devices, connected to each other, or they could have thousands. Network devices are connected together in a variety of ways, such as copper wire cables, optical, wireless or other methods. We will dive deeper into these transmission mediums later.&lt;/p&gt;

&lt;p&gt;In the past, there were networks for many different things. Analog telephone networks were used for making telephone calls. Video would be on a separate network, and digital computer data would be have its own network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fold-phone-network-1024x806.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fold-phone-network-1024x806.jpg" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, as technology improved, companies began to merge these communication services together to create what’s called a converged network.&lt;/p&gt;

&lt;h3&gt;
  
  
  Converged networks
&lt;/h3&gt;

&lt;p&gt;Converged networks, are networks where all different types of traffic is combined. In contrast to the separate networks described above, voice, video and data all travel over the same network.&lt;/p&gt;

&lt;p&gt;A smartphone doesn’t care whether you’re making a voice call, sending a message or browsing the Web using a data connection. In fact, the smartphone and carrier, treat the traffic the same. That is, digital data going out, over a digital network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F06%2FUntitled-Diagram3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F06%2FUntitled-Diagram3.png" alt="A diagram of a converged network, containing voice, data and video traffic sent digitally." width="800" height="400"&gt;&lt;/a&gt;Converged network – voice, data &amp;amp; video. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Availability&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As you probably know, we rely heavily upon networks. Networks are all around us and, we expect them to be available to us almost all of the time. This availability is measured using uptime.&lt;/p&gt;

&lt;h4&gt;
  
  
  Network uptime
&lt;/h4&gt;

&lt;p&gt;Network uptime measures a networks availability. Business networks expect 99.999% uptime, also known as the five nines of availability. If you do the math, that works out to about 5 minutes of downtime each year.&lt;/p&gt;

&lt;p&gt;Companies pay for and expect that level of availability. Engineers, technicians and others work hard to maintain the network and keep data moving.&lt;/p&gt;

&lt;h4&gt;
  
  
  Network traffic
&lt;/h4&gt;

&lt;p&gt;Network traffic describes the type of data being sent over the network. Effective maintenance of a network requires knowing what kind of traffic to expect. Here are some common traffic types:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F06%2FUntitled-Diagram4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F06%2FUntitled-Diagram4.png" alt="A diagram illustrating different types of network traffic." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File sharing&lt;/li&gt;
&lt;li&gt;Video streaming&lt;/li&gt;
&lt;li&gt;Web&lt;/li&gt;
&lt;li&gt;VoIP&lt;/li&gt;
&lt;li&gt;Email&lt;/li&gt;
&lt;li&gt;Messaging&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are new types of traffic being created all the time. Familiarize yourself with these different traffic types as you learn to maintain a network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Network Components
&lt;/h2&gt;

&lt;p&gt;Network components are components that actually make up a network, in order to move data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Client
&lt;/h4&gt;

&lt;p&gt;Clients are devices that are used by end-users to access a network. For example, these could be tablets, smartphones, laptops, servers or other &lt;a href="https://en.wikipedia.org/wiki/Terminal_(telecommunication)" rel="noopener noreferrer"&gt;terminal&lt;/a&gt; device.&lt;/p&gt;

&lt;h4&gt;
  
  
  Server
&lt;/h4&gt;

&lt;p&gt;Servers provide resources to the network. Since there are many different types of resources, there is of course many types of servers. Some examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mail servers&lt;/li&gt;
&lt;li&gt;File servers &lt;/li&gt;
&lt;li&gt;Web servers&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://blog.jordanholt.dev/what-is-a-domain-name-and-how-does-dns-work/" rel="noopener noreferrer"&gt;DNS&lt;/a&gt; servers&lt;/li&gt;
&lt;li&gt;Chat servers&lt;/li&gt;
&lt;li&gt;Print servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Servers are can be hardware or software, with varying degrees of complexity, but they all provide resources. Without a doubt, this is a big topic, so we will dive deeper to servers in future articles.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hub
&lt;/h4&gt;

&lt;p&gt;Hubs connect network devices together. However, they are an older technology and as such, are not commonly used. &lt;/p&gt;

&lt;p&gt;Because hubs rebroadcast information received on one port, to all the other ports, errors can occur. Because hubs essentially act as repeaters, only one conversation can occur at anytime. As a result hubs use a method called &lt;a href="https://en.wikipedia.org/wiki/Carrier-sense_multiple_access_with_collision_detection" rel="noopener noreferrer"&gt;CSMA/CD&lt;/a&gt;. to avoid collisions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Wireless Access Point
&lt;/h4&gt;

&lt;p&gt;Wireless access point (WAP), are devices that allow wireless-enabled clients connect into a wired network. This connection is similar to hubs. That is, anything received one way, is broadcast the other way.&lt;/p&gt;

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

&lt;p&gt;In a similar way to how older hubs worked, switches connect devices together. However, switches do not broadcast a copy of the information to all connected devices. Instead, switches learn what devices are connected to each port, and broadcast data directly to the intended device.&lt;/p&gt;

&lt;p&gt;To illustrate the difference, think of hubs as someone who sends a message to a group of people. While a switch only sends the message directly to certain members of the group.&lt;/p&gt;

&lt;p&gt;As a result, switches increase security and performance compared with hubs. Lastly, switches use the MAC address of connected devices, to make decisions on which port to broadcast the data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Router
&lt;/h4&gt;

&lt;p&gt;Routers connect two different networks together. They route traffic using logical addresses, better known as IP addresses. However, there are other routing protocols in use that don’t use IP addresses.&lt;/p&gt;

&lt;h4&gt;
  
  
  Media
&lt;/h4&gt;

&lt;p&gt;Media is used to actually connect devices to other components such as a switch port. For example, copper cable, fiber and radio waves are all types of media.&lt;/p&gt;

&lt;p&gt;Every media type has different characteristics, and as a result they will have their own strengths, weaknesses and applications.&lt;/p&gt;

&lt;h4&gt;
  
  
  Wide Area Network (WAN) link
&lt;/h4&gt;

&lt;p&gt;WAN link is simply a connection that joins two or more geographically dispersed networks together. The Internet is basically a series of WAN links. As you probably assumed, there are many different types of WAN links, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dial-up &lt;/li&gt;
&lt;li&gt;Cable&lt;/li&gt;
&lt;li&gt;Cellular &lt;/li&gt;
&lt;li&gt;Leased line&lt;/li&gt;
&lt;li&gt;Satellite &lt;/li&gt;
&lt;li&gt;Microwave link&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The WAN links are routed through a router and into a local network. Essentially, WAN links connect internal networks to external ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;Networks are all around us in our daily life. We rely on these networks for critical and demanding tasks. As a result, have come to expect them to be available all the time. Even if you’re not maintaining a network yourself, a basic understanding of networks can go a long way towards improving your skills.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://blog.jordanholt.dev/networks-and-network-components/" rel="noopener noreferrer"&gt;Important Network Concepts for Beginners&lt;/a&gt; appeared first on &lt;a href="https://blog.jordanholt.dev" rel="noopener noreferrer"&gt;Jordan Holt&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>internet</category>
      <category>networkarchitecture</category>
    </item>
    <item>
      <title>What you need to know about URLs</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Sat, 21 Aug 2021 14:38:38 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/what-you-need-to-know-about-urls-22ik</link>
      <guid>https://forem.com/jordanholtdev/what-you-need-to-know-about-urls-22ik</guid>
      <description>&lt;p&gt;URLs are one of the pillars of Web architecture, and a key concept for anyone who codes. This article discusses URLs, what they are, how they are used and how they are made.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are URLs?
&lt;/h2&gt;

&lt;p&gt;Uniform Resource Locators, better known as URLs, are simply addresses that point to unique resource. They are a type of URI, which stands for Uniform Resource Identifier.&lt;/p&gt;

&lt;p&gt;Often called a web address in the context of HTTP, a URL is an address that points to resource, such as an HTML page or an image for example. URLs are used by browsers to load the associated resource.&lt;/p&gt;

&lt;p&gt;Here is an example of a URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.google.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can type this URL into the address bar of a browser, and the browser will retrieve the resource for us.&lt;/p&gt;

&lt;p&gt;In this example, the resource is the Google homepage:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Furl-into-address-bar.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Furl-into-address-bar.gif" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we enter this URL into the address bar of a browser, an HTTP request is sent to a server that is managing the resource. In this case specifically, a &lt;code&gt;GET&lt;/code&gt; &lt;a href="https://blog.jordanholt.dev/server-requests-with-powershell/" rel="noopener noreferrer"&gt;request&lt;/a&gt; is to the server that is hosting the Google homepage.&lt;/p&gt;

&lt;p&gt;We can see the network request made by the browser, by using the browsers built-in &lt;a href="https://dev.to/jordanholtdev/getting-started-with-firefox-nm7"&gt;developer tools&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Ffirefox-network-request.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Ffirefox-network-request.png" alt="A photo of the network inspector in FIrefox browsers developer tools. Pictures the request information and URL information." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the request information, it contains the follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scheme: The scheme used in the URL&lt;/li&gt;
&lt;li&gt;Host: The server &lt;/li&gt;
&lt;li&gt;Filename: The full path to the resource&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s have a closer look at these elements, and the structure of a URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structure of a URL
&lt;/h2&gt;

&lt;p&gt;Every URL consists of a number of different parts. Some of these parts are optional while others are mandatory. You will probably recognize many of these components.&lt;/p&gt;

&lt;p&gt;Here is an example of a basic URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-basic-syntax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-basic-syntax.png" alt="A diagram of the structure of an HTTP URL." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s discuss the details further.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scheme
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FUntitled-Diagram.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FUntitled-Diagram.png" alt="Diagram showing examples of different schemes commonly used in URLs" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first part of a URL is the &lt;em&gt;scheme&lt;/em&gt;. URL is used to ‘locate’ a resource, the scheme tells us ‘how’ we to access that resource. It indicates what protocol to use to access the resource.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fmailto-url-example.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fmailto-url-example.gif" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Browsers are capable of accepting different schemes such as &lt;code&gt;mailto:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Often the protocol is HTTP or HTTPS, when using a browser to access a web page. However there are many schemes available. Here are some examples of other schemes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http:
mailto:
ftp:
telnet:
news:
tel:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Authority
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Syntax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Syntax.png" title="Diagram of authoriy component" alt="An example of the authority component of a URL." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the scheme, is the &lt;em&gt;authority&lt;/em&gt; component. It indicates what server manages the resource. It includes two elements,the &lt;em&gt;host&lt;/em&gt; and the &lt;em&gt;port&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The authority component is separated from the scheme by &lt;code&gt;://&lt;/code&gt; the colon indicates a different part of the URL, and the &lt;code&gt;//&lt;/code&gt; means the authority will be next.&lt;/p&gt;

&lt;p&gt;However, not all URLs use authority. It is important to understand the requirements of each protocol. Consider the following examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/blog
mailto:example@example.com?subject=hello
news:&amp;lt;message-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Host
&lt;/h4&gt;

&lt;p&gt;In the HTTP context, the host is often a qualified domain but it could also be an IPv4 or IPv6 address.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Syntax1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Syntax1.png" alt="Example of the Host &amp;amp; port elements found in a typical URL." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Port
&lt;/h4&gt;

&lt;p&gt;This number indicates which &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Port" rel="noopener noreferrer"&gt;port&lt;/a&gt; to connect to. The port is a communication endpoint. In an HTTP URL scheme, if the port number is omitted, then the port will default to port 80.&lt;/p&gt;

&lt;p&gt;URL schemes usually define the port numbers for the protocol. When the port number is omitted, the colon separating them will be omitted too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:80
http://192.168.0.1:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Path
&lt;/h3&gt;

&lt;p&gt;The URL &lt;em&gt;path&lt;/em&gt; contains information about how to access the resource. It is the path to the resource. The path syntax depends on which URL scheme is being used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-path.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-path.png" alt="Diagram of a URL, highlighting the path element." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In HTTP URLs, the &lt;code&gt;/&lt;/code&gt; indicates a hierarchical structure – in the example above, &lt;code&gt;archive&lt;/code&gt; is a child of &lt;code&gt;blog&lt;/code&gt;. Note that the &lt;code&gt;/&lt;/code&gt; separating the host and the path is not part of the path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parameters
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Furl-params-diagram.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Furl-params-diagram.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Parameters are a list of key value pairs that are used by servers to perform some action before returning the resource. We can observe this by using the Google Search engine.&lt;/p&gt;

&lt;p&gt;When you enter a term in the search bar, the term is then included as a URL parameter and processed by the server before returning the resource. We can confirm this by looking at the URL in the address bar:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Param-Example-2-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Param-Example-2-1.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTPS URL.&lt;/strong&gt; The browser sends an HTTP &lt;code&gt;GET&lt;/code&gt; request including the search term as a parameter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Param-Example-1-edited.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2FURL-Param-Example-1-edited.png" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Address bar.&lt;/strong&gt; Notice the parameters, consisting of key/value pairs.&lt;/p&gt;

&lt;p&gt;Every server will handle parameters differently, so it’s important to verify with the owner how they are specifically handled.&lt;/p&gt;

&lt;h2&gt;
  
  
  URLs in HTML
&lt;/h2&gt;

&lt;p&gt;As previously mentioned, we can enter a URL directly into the address bar of a browser to access a resource. However, there are many technologies that use URLs, such as HTML, CSS and JavaScript. Let’s have a have a look at how URLs are used in HTML.&lt;/p&gt;

&lt;p&gt;HTML extensively uses URLs to access documents and move from one to another. Whenever you click a hyperlink, and navigate to another HTML page, you are using a URL. A hyperlink is simply text that is tied to a URL.&lt;/p&gt;

&lt;p&gt;Links to other documents are created in HTML, using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a" rel="noopener noreferrer"&gt;&amp;lt;&lt;code&gt;a&amp;gt;&lt;/code&gt;&lt;/a&gt; element. This allows users to quickly access the desired document.&lt;/p&gt;

&lt;p&gt;Here is an example of a link using the &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element in HTML:&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;a href="https://example.com"&amp;gt;This is text that is tied to a URL&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fhyperlink.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fwp-content%2Fuploads%2F2021%2F08%2Fhyperlink.gif" alt="An example of a hyperlink being clicked. Hyperlinks simply URLs tied to text." width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;We have only scratched the surface of what URLs are and what they are used for. In future posts we will have a closer look at how we use URLs with JavaScript, including the URL web API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Further reference
&lt;/h3&gt;

&lt;p&gt;For those who are interested in further reading on the subject.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml" rel="noopener noreferrer"&gt;URI Schemes List – IANA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://url.spec.whatwg.org/" rel="noopener noreferrer"&gt;URL Specification – WHATWG&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding" rel="noopener noreferrer"&gt;Percent-encoding – MDN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://blog.jordanholt.dev/what-you-need-to-know-about-urls/" rel="noopener noreferrer"&gt;What you need to know about URLs&lt;/a&gt; appeared first on &lt;a href="https://blog.jordanholt.dev" rel="noopener noreferrer"&gt;Jordan Holt&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>web</category>
    </item>
    <item>
      <title>Fundamentals of Cloud Computing</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Thu, 03 Dec 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/fundamentals-of-cloud-computing-4i46</link>
      <guid>https://forem.com/jordanholtdev/fundamentals-of-cloud-computing-4i46</guid>
      <description>&lt;p&gt;The demand for qualified individuals in cloud computing is on the rise and it doesn't look to be slowing down. As more industries start to transition to a cloud model the demand for cloud skills will continue to grow. The global public cloud revenue is expected to grow to over 💲300B in 2021.&lt;/p&gt;

&lt;p&gt;Now is a great time to learn a new skill and familiarize yourself with the rapidly changing field.&lt;/p&gt;

&lt;p&gt;But where should you start? In this article we'll start with the basics and learn all about cloud computing fundamentals.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the cloud?
&lt;/h2&gt;

&lt;p&gt;The term cloud is basically referring to a data center or multiple data centers that are connected to each other, and are then made available to users through the internet. Instead of having to manage computer resources, they can be accessed via the cloud on demand.&lt;/p&gt;

&lt;p&gt;Users do not have to directly manage the hardware or software, they can simply click to access these computing resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fstatic%2Fa47179bcd1307c95893adfdc7c85c78b%2F8c557%2Fcloud-diagram.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.jordanholt.dev%2Fstatic%2Fa47179bcd1307c95893adfdc7c85c78b%2F8c557%2Fcloud-diagram.png" title="a diagram of cloud computing" alt="a diagram of cloud computing" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Data centers &amp;amp; hosting providers
&lt;/h2&gt;

&lt;p&gt;To better understand what cloud computing is, let's first look at what a typical workflow might look like for a company before cloud computing became so popular.&lt;/p&gt;

&lt;p&gt;Let's say a company wanted to host a website. They might have a system administrator who will be responsible for the configuration and operation of the server that hosts the website.&lt;/p&gt;

&lt;p&gt;The sysadmin might be responsible for helping to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Evaluate and choose the data center or hosting provider&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Determine and provide server requirements to data center / hosting provider&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Negotiate final services&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any issues or problems that arrive require the sysadmins attention. Let's have a closer look at the two main methods of acquiring servers or computer resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data centers
&lt;/h3&gt;

&lt;p&gt;Before cloud computing became so popular, companies often directly dealt with &lt;a href="https://en.wikipedia.org/wiki/Data_center" rel="noopener noreferrer"&gt;data centers&lt;/a&gt;. A data center can house thousands of servers owned by private companies or individuals. They also might rent physical servers to companies who don't provide their own.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dedicated space designed to house computer systems and any associated technology.&lt;/li&gt;
&lt;li&gt;Data centers can contain redundant systems such as power backups and environmental controls&lt;/li&gt;
&lt;li&gt;Data centers can help provide physical security to the servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Any additional server specifications require a technician to physically implement -e.g., someone physically installs additional RAM&lt;/li&gt;
&lt;li&gt;While the data center might have redundant systems and protections, if the entire facility failed so would the server.&lt;/li&gt;
&lt;li&gt;The negotiations and pricing process can take some time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Negotiating and pricing requires a bit more effort with data centers as the server configuration, associated components such as internet connection, power and cooling need to be determined. When you're dealing larger projects this process can take a long time and if rushed can end up costing a lot of money.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hosting providers
&lt;/h3&gt;

&lt;p&gt;Generally with a hosting provider, instead of buying or renting a physical server in a data center you pay a monthly fee and get a dedicated server, the hosting provider takes care of the rest. You choose the available servers that the hosting provider offers and any additional configuration. The hosting provider deals with all the physical requirements of the server. A hosting provider is often just a company that owns servers in a data center and charges a fixed price to rent those managed servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monthly fixed price for dedicated server.&lt;/li&gt;
&lt;li&gt;Easier to get started and configure&lt;/li&gt;
&lt;li&gt;The hosting provider will connect with the data center to implement changes to your server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Any additional server specifications require a support ticket - .e.g., contact the hosting provider to request additional RAM, response time will vary.&lt;/li&gt;
&lt;li&gt;Cost can be steep. Pay a fixed price regardless of usage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the biggest downsides of a hosting provider besides the fixed cost, is the reliance on them to implement changes to the server in timely manner. For example, if you want to increase the RAM you submit a ticket and then wait for them to respond. Response times will vary and in fact it can be an additional cost for priority support.&lt;/p&gt;

&lt;p&gt;So far we've looked at two ways to acquire computer resources. Data centers, where a physical server is housed and hosting providers that charge a fixed monthly fee for a dedicated server. With those options, we either have to have someone physically upgrade our server, or in the case of the hosting provider, create a ticket and wait for them to apply the upgrades.&lt;/p&gt;

&lt;p&gt;Let's look at how cloud computing helps us avoid those obstacles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro to cloud computing
&lt;/h2&gt;

&lt;p&gt;Cloud computing is a model that makes computer resources available as a service. Users can easily launch these services without any human intervention. No more waiting around to hear back from a data center or hosting provider.&lt;/p&gt;

&lt;p&gt;Here are three of the main characteristics of cloud computing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Services are on-demand &amp;amp; self-serviced&lt;/strong&gt; - A user can implement without any manual intervention.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elasticity&lt;/strong&gt; - Must be able to scale up and down anytime&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measured&lt;/strong&gt; - Only pay for what you used, no fixed cost.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cloud computing providers offer their services via three main models. Cloud providers may offer services in more than model, or they might only specialize in one area.&lt;/p&gt;

&lt;h3&gt;
  
  
  Software as a service (SaaS)
&lt;/h3&gt;

&lt;p&gt;In the SaaS model, the cloud providers install an application in the cloud and handle all the infrastructure and necessary platforms for the application to run. Users can access the application from cloud clients, this way users do not need to download or install the application. The application is running in the cloud and it can be accessed via the browser.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/" rel="noopener noreferrer"&gt;Google Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.microsoft.com/en-ca/microsoft-365" rel="noopener noreferrer"&gt;Microsoft 360&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Platform as a service (PaaS)
&lt;/h3&gt;

&lt;p&gt;In this model cloud providers will setup the necessary infrastructure and platforms for users to develop an application. This can include an operating system, web server and other necessary elements. Users can then develop and deploy applications on that platform.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/appengine" rel="noopener noreferrer"&gt;Google App Engine&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-ca/services/app-service/" rel="noopener noreferrer"&gt;Microsoft Azure App Service&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Infrastructure as a service (IaaS)
&lt;/h3&gt;

&lt;p&gt;As its name suggests, this model provides infrastructure as a service. Typically this means things like servers and databases.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/" rel="noopener noreferrer"&gt;Digital Ocean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/" rel="noopener noreferrer"&gt;AWS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cloud providers
&lt;/h2&gt;

&lt;p&gt;There is no shortage of choice when looking for a cloud provider. It can be very easy to spend unnecessary money if you rush to decide.&lt;/p&gt;

&lt;p&gt;Take your time when deciding, most of the cloud providers have some sort of free tier if you're interested in trying before buying.&lt;/p&gt;

&lt;p&gt;Here are a few popular cloud providers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-us/" rel="noopener noreferrer"&gt;Microsoft Azure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/" rel="noopener noreferrer"&gt;Amazon Web Services (AWS)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com" rel="noopener noreferrer"&gt;Google Cloud Platform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oracle.com/cloud/" rel="noopener noreferrer"&gt;Oracle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.alibabacloud.com/campaign/free-trial" rel="noopener noreferrer"&gt;Alibaba Cloud&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are a number of smaller providers out there. Not all of them will offer the comprehensive computing services that AWS or Azure will but they might be more economical.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;In this article we saw that the cloud is really just a data center or multiple data centers that are made available through the internet. We saw how things were often done before the cloud became popular.&lt;/p&gt;

&lt;p&gt;We learned about the characteristics of cloud computing and looked at different cloud models like SaaS, PaaS and IaaS and some of the major providers. We also began to look at the architecture of cloud environments. In future articles we'll dive deeper into the infrastructure of the cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.ovhcloud.com/en-ca/bare-metal/advance/prices/" rel="noopener noreferrer"&gt;Hosting Provider / Dedicated servers / Cloud - OVH&lt;/a&gt; - This is a well known hosting provider that also provides cloud services.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/" rel="noopener noreferrer"&gt;Cloud Provider - Digital Ocean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nist.gov/" rel="noopener noreferrer"&gt;National Institute of Standards and Technology&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://free-for.dev/#/" rel="noopener noreferrer"&gt;Free for dev &lt;/a&gt; - Large list of SaaS, IaaS and PaaS services, aimed at DevOp/SysAdmin&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>learning</category>
      <category>cloud</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript Scope: What is it?</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Fri, 27 Nov 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/javascript-scope-what-is-it-cc3</link>
      <guid>https://forem.com/jordanholtdev/javascript-scope-what-is-it-cc3</guid>
      <description>&lt;p&gt;In JavaScript, the concept of scope relates to where variables and expressions can be accessed from. In this article we'll look at a few different types of scope, what they do and how you use scope to improve the performance of a program.&lt;/p&gt;

&lt;p&gt;If you're just starting out, check out my article on &lt;a href="https://blog.jordanholt.dev/what-is-javascript-scope/" rel="noopener noreferrer"&gt;JavaScript variables&lt;/a&gt; which is a good introduction to scope.&lt;/p&gt;

&lt;p&gt;Here's what &lt;a href="https://developer.mozilla.org/en-US/" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; says about scope:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The current context of execution. The context in which values and expressions are "visible" or can be referenced&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The current context of a value or expression will determine where they are made available. So how do we determine the current context? We look at the location of the variable. This is because JavaScript has &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures" rel="noopener noreferrer"&gt;lexical scoping&lt;/a&gt; and closures. Lexical scoping basically means that JavaScript will use the location of where a variable is declared, to determine where the variable is available.&lt;/p&gt;

&lt;p&gt;This means that we can read the source code to determine the scope.&lt;/p&gt;

&lt;p&gt;Let's look at 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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;()&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;animal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Lion&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="c1"&gt;// code can use animal inside this function&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Code outside of the function can't use animal&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code outside of the function cannot access the variable that was declared inside the function. In this context the variable &lt;code&gt;animal&lt;/code&gt; would be known to have local scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope types
&lt;/h2&gt;

&lt;p&gt;There are four scopes in JavaScript, they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Global Scope - Global scoped values and expressions are visible by everything.&lt;/li&gt;
&lt;li&gt;Block Scope - The values and expressions are only visible within the code block and any sub-blocks&lt;/li&gt;
&lt;li&gt;Module Scope - Values and expressions are visible within the module.&lt;/li&gt;
&lt;li&gt;Function Scope - Visible within the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Global scope
&lt;/h2&gt;

&lt;p&gt;If you declare a variable outside of any function than it is known to have global scope. Global variables go to the global namespace which allow the variables to be accessed anywhere in the 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="c1"&gt;// this is a global variable, it was declared outside of any function.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;animal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&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="c1"&gt;// this is a local variable, it is declared inside a function.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;woof&lt;/span&gt;&lt;span class="dl"&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;sound&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 'woof'&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;sound&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: sound is not defined&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;animal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: dog&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example about the first variable &lt;code&gt;animal&lt;/code&gt; has been declared outside of any function, this is known as a global variable and its value is accessible in the global scope. Inside the function called &lt;code&gt;sayHello&lt;/code&gt;, there is a variable &lt;code&gt;sound&lt;/code&gt;. Because &lt;code&gt;sound&lt;/code&gt; was declared inside a function, it is known to have local scope, and its values are only accessible inside of the function it was declared.&lt;/p&gt;

&lt;p&gt;When we attempt to log the value of &lt;code&gt;sound&lt;/code&gt; we receive a &lt;code&gt;Reference Error&lt;/code&gt; because in that context, &lt;code&gt;sound&lt;/code&gt; does not exist, it is out of scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Block scope
&lt;/h2&gt;

&lt;p&gt;Prior to ECMAScript 2015 and the &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords, JavaScript didn’t have block statement scope. So a variable declared inside a block is local to the scope that the block is in.&lt;/p&gt;

&lt;p&gt;Observe 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="k"&gt;if &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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&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;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Ouput: 5&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;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: ReferenceError: age is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that we are able to access the &lt;code&gt;counter&lt;/code&gt; variable from outside of the &lt;code&gt;if&lt;/code&gt; code block. However when we try and log the &lt;code&gt;age&lt;/code&gt; variable we recieve an error because the &lt;code&gt;let&lt;/code&gt; variable is block-scoped.&lt;/p&gt;

&lt;p&gt;Before the &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords were introduced in ECMAScript 2015, variables did not have block scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Module scope
&lt;/h2&gt;

&lt;p&gt;With the introduction of modules in ECMAScript 2015 came module scope. Modules allow us to split up code and seperate concerns in a program. Code contained inside modules needs to be imported into a script to be used. The code is then imported into the scope of that specific script, the code in the module is not globally scoped.&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;// feature.js is a javascript module&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;counter&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;anotherFunction&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;counter&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;&lt;code&gt;someFunction&lt;/code&gt; is declared inside a module. To access this function, it needs to be exported from the module and imported into the chosen script.&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;// app.js is the chosen script&lt;/span&gt;
&lt;span class="k"&gt;import&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="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../feature.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="nf"&gt;someFunction&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;// Output: 2&lt;/span&gt;

&lt;span class="nf"&gt;anotherFunction&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;// Ouput: ReferenceError: anotherFunction is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above we import the &lt;code&gt;someFunction&lt;/code&gt; from the module and import it into the &lt;code&gt;app.js&lt;/code&gt; script where it can be used. However, when we try and invoke &lt;code&gt;anotherFunction&lt;/code&gt; we get a reference error because the module scope prevents us from accessing those values unless it is properly imported and exported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope pollution
&lt;/h2&gt;

&lt;p&gt;When there are too many variables in the global namespace then there is a possibility of name collision, especially if you're using many different libraries. Generally global scoped variables should be reserved for objects that have program-wide relevance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;In this article we learned about the basics of scope in JavaScript. We looked at 4 different types of scope and how to determine them by looking at the source code. Scope is an important concept to understand in JavaScript and one that will be leveraged every time you code. Make sure to check out the references below for more information on JavaScript scopes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reference
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Scope" rel="noopener noreferrer"&gt;Scope - MDN &lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.ecma-international.org/ecma-262/#sec-lexical-environments" rel="noopener noreferrer"&gt;Lexical Environment - ECMA &lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript/500459#500459" rel="noopener noreferrer"&gt;What is the scope of variables in javascript? - Stack Overflow&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures" rel="noopener noreferrer"&gt;Closures - MDN &lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>learning</category>
    </item>
    <item>
      <title>JavaScript: Tagged template literals</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Fri, 20 Nov 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/javascript-tagged-template-literals-1cfb</link>
      <guid>https://forem.com/jordanholtdev/javascript-tagged-template-literals-1cfb</guid>
      <description>&lt;p&gt;The template literal syntax is a very useful feature in JavaScript. One often overlooked feature of template literals is the ability to use a tag function to perform actions on them. Instead of immediately assigning the template literals to a variable we can pass their values as arguments, to a function. The function will then process those arguments anyway we want and return us something, often that will be a string but it could be anything.&lt;/p&gt;

&lt;p&gt;Let's have a look at how we can put a tagged template literal together. But first let's have a quick refresh of the template literal syntax.&lt;/p&gt;

&lt;p&gt;Template literals are enclosed with backticks &lt;code&gt;(&lt;/code&gt;&lt;code&gt;)&lt;/code&gt;, and can contain placeholders for 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;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;89453&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;API_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://examplesite.com/blogs/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;API_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: "https://examplesite.com/blogs/89453"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This syntax is very powerful and is used in many programs for a variety of tasks. For example you'll often see template literals used when making making a network request to an outside API.&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/CSS-in-JS" rel="noopener noreferrer"&gt;CSS-in-JS&lt;/a&gt; libraries is another place you might frequently see template literals:&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;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StyledButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  border-radius: 3px;
  padding: 0.5rem 0;
  margin: 0.5rem 1rem;
  background: orange;
  color: white;
  border: 2px solid white;
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tagged template literal allows us to run a template literal through a function as opposed to assigning it a value immediately.&lt;/p&gt;

&lt;p&gt;Here's how to create a tagged template literal:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a function&lt;/li&gt;
&lt;li&gt;Create a template string&lt;/li&gt;
&lt;li&gt;Take the name of the function and put it in front of the template literal.
&lt;/li&gt;
&lt;/ol&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;applyDeal&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="c1"&gt;// some processing logic&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;fruitType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Citrus&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;applyDeal&lt;/span&gt;&lt;span class="s2"&gt;`Today only, we have a great deal on &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fruitType&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; fruit. Currently only &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;deal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once a template literal has been tagged, the browser will run this function and pass in the information. We can add some logic to process the template literal and whatever we return from the function will get assigned to the &lt;code&gt;deal&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;The function will take a couple of arguments. The first argument are all the pieces of string which we'll pass in as a parameter called &lt;code&gt;strings&lt;/code&gt;. Then we can pass in the other values we used in the placeholders, we can pass in a &lt;code&gt;price&lt;/code&gt; and &lt;code&gt;fruitType&lt;/code&gt; or take advantage of the &lt;code&gt;rest&lt;/code&gt; operator and pass in &lt;code&gt;...values&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;applyDeal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;values&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="nx"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;values&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 is logged to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Today only, we have a great deal on "&lt;/span&gt;, &lt;span class="s2"&gt;" fruit. Currently only "&lt;/span&gt;, &lt;span class="s2"&gt;"!!"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;,
  &lt;span class="s2"&gt;"Citrus"&lt;/span&gt;,
  5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The argument &lt;code&gt;strings&lt;/code&gt; is an array of string pieces that were separated by the placeholders in the template literal. The &lt;code&gt;..values&lt;/code&gt; are the expression values that the placeholders contain, in this case with the value &lt;code&gt;"Citrus"&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have access to those values in the &lt;code&gt;applyDeal&lt;/code&gt; function we can add some logic.&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;applyDeal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;values&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="c1"&gt;// some processing logic&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringOne&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strings&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringTwo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strings&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stringThree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;strings&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;let&lt;/span&gt; &lt;span class="nx"&gt;msgStr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&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;values&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="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;msgStr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`!!DEAL ALERT!! `&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;msgStr&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;stringOne&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;stringTwo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;$&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;values&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;stringThree&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;fruitType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Citrus&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;applyDeal&lt;/span&gt;&lt;span class="s2"&gt;`Today only, we have a great deal on &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fruitType&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; fruit. Currently only &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;deal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: "!!DEAL ALERT!! Today only, we have a great deal on  fruit. Currently only $5!!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above is fairly straight forward, we pass in the string and values to the function and then we have some conditional logic that checks to see if the second value (in this case that is &lt;code&gt;5&lt;/code&gt;) is less than 10, if it is then we assign &lt;code&gt;"!!DEAL ALERT!!"&lt;/code&gt; to a variable and then finally return another template literal which will be assigned to the variable &lt;code&gt;deal&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Obviously this isn't the most practical example, but it does highlight how powerful tagged template literals can be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;There are a ton of different uses for tagged template literals in JavaScript. In this article you saw the basic structure of tagged template literals. A tag function can perform actions on those arguments and then return another string or whatever your use case requires.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" rel="noopener noreferrer"&gt;Template literals - MDN-&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/27678052/usage-of-the-backtick-character-in-javascript" rel="noopener noreferrer"&gt;Backticks in JavaScript - Stack Overflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-work-with-strings-in-javascript" rel="noopener noreferrer"&gt;How to work with strings in JavaScript - DigitalOcean&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>learning</category>
    </item>
    <item>
      <title>Create a modal overlay using JavaScript</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Sun, 15 Nov 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/create-a-modal-overlay-using-javascript-36cd</link>
      <guid>https://forem.com/jordanholtdev/create-a-modal-overlay-using-javascript-36cd</guid>
      <description>&lt;p&gt;One common feature in many web pages and apps are modals. Modal windows and overlays serve as structural elements for many differenet types of content, such as images and videos, forms, alerts and notices and others like search boxes. Becoming familiar with modals and the various ways they can be created is a great way to practice your skills as a front-end developer and has been known to be included during interviews.&lt;/p&gt;

&lt;p&gt;In this article we'll create a simple modal overlay that contains a newsletter sign-up form, using HTML, CSS and JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;We have a web page and we need to collect email addresses for a newsletter. To do this we will create a dismissible modal overlay. A user should be able to click on a "Subscribe" button which will open the modal overlay that will contain a basic sign up form. The sign up form will collect a users name and email address. If the user successfully submits the form a success message will briefly appear.&lt;/p&gt;

&lt;p&gt;Here's what the final product will look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ysfde2d9zfn4icfcbf9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ysfde2d9zfn4icfcbf9.gif" alt="final-product" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here's a link to the final source code on &lt;a href="https://codepen.io/aaronsonish/pen/dyXaxOL" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The user should be able to dismiss the modal by clicking an "X" or clicking anywhere outside of the modal.&lt;/p&gt;

&lt;p&gt;Let's break these requirements down further:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create "Subscribe" button

&lt;ul&gt;
&lt;li&gt;User can click button and enable the modal.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Create modal overlay

&lt;ul&gt;
&lt;li&gt;Must be centered vertically and horizontally.&lt;/li&gt;
&lt;li&gt;The modal will contain a CTA and a form.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Modal contains form to collect name and email&lt;/li&gt;
&lt;li&gt;User can submit the form&lt;/li&gt;
&lt;li&gt;User can dismiss the modal

&lt;ul&gt;
&lt;li&gt;User can click "x" button to dismiss.&lt;/li&gt;
&lt;li&gt;User can click anywhere outside of the modal to dismiss&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When a form is submitted, the modal is closed and a "Success" message is shown.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a mockup of the form:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ct3kn55plalbzqlf1gy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ct3kn55plalbzqlf1gy.jpg" alt="modal-mock" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Let's start off by creating a "Subscribe" button that the user can click, as well as the basic structure of our modal.&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;button&amp;gt;&lt;/span&gt;Subscribe&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- modal overlay --&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;"modal-overlay"&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;"modal"&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;"modal-close"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;X&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;"modal-content"&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;Subscribe now!&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;Subscribe to get a free PDF!&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&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;After the button, we can create the structure of the modal. It is made up of two main elements, the &lt;code&gt;div&lt;/code&gt; with the class name &lt;code&gt;modal-overlay&lt;/code&gt; and then the modal itself which is composed of a &lt;code&gt;div&lt;/code&gt; with the class name &lt;code&gt;modal&lt;/code&gt; and it's children.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;modal-overlay&lt;/code&gt; will encompass the entire viewport when enabled, and showcase the modal. We will add some styling to the overlay to focus the users attention on the modal itself.&lt;/p&gt;

&lt;p&gt;Currently we have a button and a bit of content but it looks awful and the user can't interact with it as intended. We'll have to add a bit of JavaScript and CSS in the next step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fymiybsbr0rz17gl1s9lo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fymiybsbr0rz17gl1s9lo.jpg" alt="step1" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's add some styles to the button and modal. Remember, we want the modal to be hidden unless a user activates the "Subscribe" button.&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="o"&gt;*&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="n"&gt;Cambria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Cochin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Georgia&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Times&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Times New Roman"&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="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;button&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="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&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;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="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&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="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&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;#18a0fb&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;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&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="nl"&gt;padding-left&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="nl"&gt;padding-right&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="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.modal-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rgba&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="m"&gt;0&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="m"&gt;0.5&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;top&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;left&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;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="nl"&gt;height&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="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.modal&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="n"&gt;Arial&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="nl"&gt;max-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="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20%&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;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;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;border-radius&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;.modal-content&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="nc"&gt;.modal-close&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;absolute&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;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&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="nl"&gt;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;Overall some basic styles but a couple of things to notice. The class &lt;code&gt;modal-wrapper&lt;/code&gt; is an important piece as this is the main overlay. It covers the entire viewport and is not displayed by default. The &lt;code&gt;background&lt;/code&gt; color has also been set to a gray color with very low opacity, this will dim the other page elements and allow the focus to remain on the modal content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Activating the modal
&lt;/h2&gt;

&lt;p&gt;Let's complete the "Subscribe" button functionality. Remember, when a user activates the button the modal overlay should appear. We'll use JavaScript to accomplish 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;buttonEl&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&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;.modal-wrapper&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;buttonEl&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="s2"&gt;click&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;block&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;First we get a reference to the button element and the &lt;code&gt;div&lt;/code&gt; with a class name of &lt;code&gt;modal-wrapper&lt;/code&gt; by and save those to variables called &lt;code&gt;buttonEl&lt;/code&gt; and &lt;code&gt;wrapper&lt;/code&gt;. Then we attach an event listener to the &lt;code&gt;buttonEl&lt;/code&gt; that listens for a "click" event. Every time the &lt;code&gt;buttonEl&lt;/code&gt; is clicked we set the &lt;code&gt;display&lt;/code&gt; property to &lt;code&gt;block&lt;/code&gt; which then reveals the &lt;code&gt;div&lt;/code&gt; element with the class name of &lt;code&gt;modal-wrapper&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fizv9qdnmkrzbvue83bh5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fizv9qdnmkrzbvue83bh5.jpg" alt="step2" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dismiss the modal
&lt;/h2&gt;

&lt;p&gt;Okay, great! We've already completed half of the requirements. We have a working "Subscribe" button that activates the modal overlay. However, right now there is no way for a user to dismiss the modal.&lt;/p&gt;

&lt;p&gt;There are two ways in which the user should be able to dismiss the modal:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User clicks the "X"&lt;/li&gt;
&lt;li&gt;User clicks anywhere outside the modal&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's implement these 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;buttonEl&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&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;.modal-wrapper&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;closeEl&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;.modal-close&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="nx"&gt;buttonEl&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="s2"&gt;click&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Block&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


&lt;span class="nx"&gt;closeEl&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="s2"&gt;click&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;wrapper&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="s2"&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;e&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modal-wrapper&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;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&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;First we store a reference to the "X" in a variable called &lt;code&gt;closeEl&lt;/code&gt;. Then we add an event listener that listens for a click, when a user clicks the &lt;code&gt;closeEl&lt;/code&gt; then the &lt;code&gt;display&lt;/code&gt; property on the &lt;code&gt;wrapper&lt;/code&gt; will be set to &lt;code&gt;none&lt;/code&gt; and the modal will close.&lt;/p&gt;

&lt;p&gt;Then we also add an event listener to the &lt;code&gt;wrapper&lt;/code&gt; itself. Because the &lt;code&gt;wrapper&lt;/code&gt; covers the entire viewport other than the modal content itself, we close the modal when the user clicks anywhere that the class name equals &lt;code&gt;modal-wrapper&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's try this out now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz5pee930xsjvpw53wqev.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz5pee930xsjvpw53wqev.gif" alt="step-3" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Add sign-up form
&lt;/h2&gt;

&lt;p&gt;Now that we have the basic structure and functionality of the modal working, let's go ahead and add the form to the modal. This will collect the users name and email.&lt;/p&gt;

&lt;p&gt;Let's add the form inside the &lt;code&gt;div&lt;/code&gt; with the class name of &lt;code&gt;modal-content&lt;/code&gt;:&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;"modal-wrapper"&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;"modal"&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;"modal-close"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;X&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;"modal-content"&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;Subscribe now!&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;Subscribe to get a free PDF!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Name:
            &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Jane Doe"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
          &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
        &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;
          &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email:
            &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
              &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"jane@example.com"&lt;/span&gt;
              &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;
              &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;
              &lt;span class="na"&gt;required&lt;/span&gt;
          &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Subscribe&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/form&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&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see it's a basic form with two &lt;code&gt;input&lt;/code&gt; elements and a &lt;code&gt;button&lt;/code&gt; to submit the form. Input validation can easily be added via HTML or JavaScript depending on your requirements, however for this example we'll leave things how they are. If you're interested in learning more about form validation, check out my article on &lt;a href="https://blog.jordanholt.dev/client-side-validation-using-built-in-form-validation/" rel="noopener noreferrer"&gt;client-side form validation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's add some more styles so the form looks a bit closer to the mockup.&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;form&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;button&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;1rem&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;2.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&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;#18a0fb&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;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&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="nl"&gt;padding-left&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="nl"&gt;padding-right&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="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;label&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="nl"&gt;padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&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;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500&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;left&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;1.25&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="nb"&gt;block&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;0px&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;solid&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="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;226&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;232&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;240&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"text"&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt;
&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"email"&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt;
&lt;span class="nt"&gt;fieldset&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;80%&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="m"&gt;#333&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="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="nl"&gt;padding-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding-right&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="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.25rem&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;solid&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="nb"&gt;inherit&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="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&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;
  
  
  Success message
&lt;/h2&gt;

&lt;p&gt;When a user enters their information into the form and clicks the submit button, it would be nice to show some sort of visual confirmation.&lt;/p&gt;

&lt;p&gt;Here's what we want to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User clicks "submit" button&lt;/li&gt;
&lt;li&gt;Modal closes&lt;/li&gt;
&lt;li&gt;Message temporarily appears indicating successful submission.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First, let's create the HTML we need for the success message, we'll put this right after the &lt;code&gt;modal-overlay&lt;/code&gt;.&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;"success-wrapper"&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;p&amp;gt;&lt;/span&gt;Success! Thank you for subscribing to the newsletter 🙏&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;And we'll add a few basic 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;.success-wrapper&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="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&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;#33ce34&lt;/span&gt;&lt;span class="n"&gt;c9&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;400px&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;45vh&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The success message will be hidden by default because of the &lt;code&gt;display&lt;/code&gt; property being set to &lt;code&gt;none&lt;/code&gt;. The message is roughly centered vertically and horizontally.&lt;/p&gt;

&lt;p&gt;Now, we can add the functionality by controlling what happens when the form is submitted.&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;buttonEl&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&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;.modal-wrapper&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;closeEl&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;.modal-close&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;form&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;form&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// highlight-line&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;successEl&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;.success-wrapper&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// highlight-line&lt;/span&gt;

&lt;span class="nx"&gt;buttonEl&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="s2"&gt;click&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Block&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;closeEl&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="s2"&gt;click&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;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;wrapper&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="s2"&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;e&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modal-wrapper&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;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&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;// highlight-start&lt;/span&gt;
&lt;span class="nx"&gt;form&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="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;wrapper&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="nx"&gt;successEl&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;block&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&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;successEl&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;display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="c1"&gt;// highlight-end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again we reference the DOM elements, in this case the &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; and the success message &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;. We attach an event listener to the &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; element to listen for &lt;code&gt;submit&lt;/code&gt; events. When a user submits the form we first prevent the default form action from executing, then we hide the modal by setting its &lt;code&gt;display&lt;/code&gt; property to &lt;code&gt;none&lt;/code&gt;. Then we use the &lt;code&gt;setTimeout()&lt;/code&gt; method to create a timer that will set the &lt;code&gt;display&lt;/code&gt; to &lt;code&gt;none&lt;/code&gt; and hide the message after 3 seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;In this article we saw how we can create a simple modal using basic HTML, CSS and JavaScript. Modals are used in many different ways and can be implemented using many different libraries or with vanilla JavaScript like we used in this example. Creating modals can be great way to practice your front-end skills, try building this modal different ways, using different tools and stretching features.&lt;/p&gt;

&lt;p&gt;Here's a link to the final code on &lt;a href="https://codepen.io/aaronsonish/pen/dyXaxOL" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation" rel="noopener noreferrer"&gt;Client-side form validation - MDN &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://designmodo.com/design-modal-windows/" rel="noopener noreferrer"&gt;Design Trends for Modal Windows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/EventListener" rel="noopener noreferrer"&gt;EventListener - MDN &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>learning</category>
    </item>
    <item>
      <title>VS Code: Configure for web development</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Fri, 13 Nov 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/vs-code-configure-for-web-development-4oa3</link>
      <guid>https://forem.com/jordanholtdev/vs-code-configure-for-web-development-4oa3</guid>
      <description>&lt;p&gt;VS Code is a powerful text editor used by web developers all over the world. One of the features that makes it particularly appealing is the high-level of customization that a user can achieve. In addition to the wide variety of options that ship with VS Code, there is a large marketplace that offers access to extensions that can be used to further fine-tune your workflow. Learning how to configure VS Code effectively for web development can help improve your workflow and make for a better experience.&lt;/p&gt;

&lt;p&gt;In this article we'll look at how we can configure VS Code for web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Before we get to deep into the settings let's have a quick look at the VS Code UI to familiarize ourselves. If you've been using VS Code as your main editor than you can probably skip this section but feel free to follow along.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffileydmku75tuh9zw0mx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffileydmku75tuh9zw0mx.jpg" alt="user-interface" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Side Bar&lt;/strong&gt;: Contains different views like the Explorer to assist you while working on your project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Editor&lt;/strong&gt;: This is where the actual code editing will take place. You can have multiple editors open at once in different layouts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Activity Bar&lt;/strong&gt;: Let's you switch between views and see relevant information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Panel&lt;/strong&gt;: This can display output and debug information as well as a built-in Terminal. Panel is collapsible for extra screen space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Status Bar&lt;/strong&gt;: Various information about the current project and files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Breadcrumbs&lt;/strong&gt;: Shows you the file type and path to allow for quick navigation. Optional.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Indent Guides&lt;/strong&gt;: These help you quickly match indent levels. Disable by setting &lt;code&gt;"editor.renderIndentGuides": false&lt;/code&gt; in workspace settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;VS Code is a well thought out application that is fairly comfortable to use right away. However, there are a number of things we can do to improve the UI as well as the functionality for use with web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic settings
&lt;/h2&gt;

&lt;p&gt;After I've installed the latest version of VS Code, I like to go through some of the basic settings and configure a few things for my preference. Everyone is going to have different requirements and preferences but here are a few of the settings that I like to adjust right away.&lt;/p&gt;

&lt;p&gt;You can access VS Code settings by navigating to &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;Preferences&lt;/code&gt; &amp;gt; &lt;code&gt;Settings&lt;/code&gt; or by pressing the &lt;code&gt;CTRL&lt;/code&gt; + &lt;code&gt;,&lt;/code&gt; keys.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1lpa28dr3x47lq2iab1m.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1lpa28dr3x47lq2iab1m.gif" alt="user-settings" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Disable &lt;a href="https://code.visualstudio.com/docs/getstarted/userinterface#_minimap" rel="noopener noreferrer"&gt;MiniMap&lt;/a&gt; - I only enable this feature when I need to search large files or look for lint errors. Generally my React modules are usually small enough that I don't need this regularly but it does have it's advantages.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2ypa9jvuh4ao061edl3e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2ypa9jvuh4ao061edl3e.jpg" alt="minimap" width="721" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enable Trim Trailing Whitespace - This removes any additional whitespace at the end of a file.&lt;/li&gt;
&lt;li&gt;Format on paste and format on save - I like to have these enabled so that Prettier can help me regularly format my code.&lt;/li&gt;
&lt;li&gt;New Window Dimensions set to &lt;code&gt;offset&lt;/code&gt; - This will determine the size of a new window when there is one open already. I often have more than one project open at a time and find this useful.&lt;/li&gt;
&lt;li&gt;Turn off Telemetry - I usually disable telemetry for applications unless there is specific requirement.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Font
&lt;/h3&gt;

&lt;p&gt;The font will have a big impact on the way the editor looks so it's important to configure it just the way you prefer. Here are a few popular ways to configure the font in VS Code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enable font ligatures. This can help improve the readability of the code. This is a preference, not all developers use ligatures. - Install &lt;a href="https://github.com/tonsky/FiraCode/wiki/VS-Code-Instructions" rel="noopener noreferrer"&gt;Fira Code&lt;/a&gt; or similar font containing ligatures.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"editor.fontWeight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"normal"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"editor.cursorWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"editor.letterSpacing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"editor.lineHeight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"editor.fontSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Color themes
&lt;/h2&gt;

&lt;p&gt;VS Code allows you to change the colors in the UI using color themes. This is one of the easiest ways to keep your project organized and a great way to inject some personality into VS Code. First thing you'll want to do is select a new color theme.&lt;/p&gt;

&lt;h3&gt;
  
  
  Select a color theme
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;Preferences&lt;/code&gt; &amp;gt; &lt;code&gt;Color Theme&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use the up and down arrow keys to preview the themes.&lt;/li&gt;
&lt;li&gt;Select a theme and press &lt;code&gt;enter&lt;/code&gt; to confirm selection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz0yi33o5kzvaua910bhk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fz0yi33o5kzvaua910bhk.gif" alt="color-theme" width="1658" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are some good color themes that come included with VS Code, however if you don't find something you like you have two options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search the &lt;a href="https://marketplace.visualstudio.com/VSCode" rel="noopener noreferrer"&gt;VS Code Marketplace&lt;/a&gt; -

&lt;ul&gt;
&lt;li&gt;Navigate to &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;Preferences&lt;/code&gt; &amp;gt; &lt;code&gt;Extensions&lt;/code&gt; or by pressing &lt;code&gt;CTRL&lt;/code&gt; + &lt;code&gt;Shift&lt;/code&gt; + &lt;code&gt;x&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enter your search. For example to search for color themes, type 'theme' into the search box.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/docs/getstarted/themes#_customizing-a-color-theme" rel="noopener noreferrer"&gt;Customize a theme&lt;/a&gt;. You can customize an active themes colors by setting the &lt;code&gt;workbench.colorCustomizations&lt;/code&gt; in user settings.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are a few popular extensions that help visually organize the code. I use these regularly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=dcasella.monokai-plusplus" rel="noopener noreferrer"&gt;Monokai++&lt;/a&gt; - One of the themes I regularly use. Monokai++ has a pleasant, modern color sheme.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme" rel="noopener noreferrer"&gt;Material Icon Theme &lt;/a&gt; - Making use of file icons is a convenient way to help clearly organize your project.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=coenraads.bracket-pair-colorizer" rel="noopener noreferrer"&gt;Bracket Pair Colorizer&lt;/a&gt; - This extension allows matching brackets to be identified with colors. No more staring at the screen trying to decipher the brackets.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow" rel="noopener noreferrer"&gt;Indent Rainbow&lt;/a&gt; - This extension provides color to the indentation in front of your text.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Workflow
&lt;/h2&gt;

&lt;p&gt;There are some really impressive extensions available for VS Code that really improves the experience for web developers. Let's have a quick look at some of the most popular VS Code extensions for web development.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tip: Extensions can impact system performance. Check extensions if you're experiencing problems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag" rel="noopener noreferrer"&gt;Auto Close Tag&lt;/a&gt; - Automatically creates the closing tag when you type the closing bracket of the opening tag.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3tz8r6phv6fqqlwadycd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3tz8r6phv6fqqlwadycd.gif" alt="auto-close-tags" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag" rel="noopener noreferrer"&gt;Auto Rename Tag&lt;/a&gt; - Automatically renames closing tags if you update the corrosponding opening tag.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets" rel="noopener noreferrer"&gt;ES7 React/Redux/GraphQL/React-Native snippets&lt;/a&gt; - Provides some commonly used snippets.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=Zignd.html-css-class-completion" rel="noopener noreferrer"&gt;IntelliSense for CSS class names in HTML&lt;/a&gt; - CSS classname completion for CSS definitions in your workspace.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense" rel="noopener noreferrer"&gt;NPM Intellisense&lt;/a&gt; - Autocompletes npm modules in import statements.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=christian-kohler.path-intellisense" rel="noopener noreferrer"&gt;Path IntelliSense&lt;/a&gt; - Extension that autocompletes filenames.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcxjgrva5bwhpk0assbh7.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcxjgrva5bwhpk0assbh7.gif" alt="path-intellisense" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Live Server&lt;/a&gt; - This extension provides an easy to use local server that features live reload. If I'm not using a framework with a dev server I am often using this extention.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=silvenon.mdx" rel="noopener noreferrer"&gt;MDX&lt;/a&gt; - MDX langauge support for VS Code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Take some time to read about the extensions that are available and ask if it solves a particular problem or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Style / Format
&lt;/h2&gt;

&lt;p&gt;Preferences will vary about styling and formatting your code, luckily VS Code makes it easy to handle different workflows. Extensions like ESLint, Prettier and &lt;a href="https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify" rel="noopener noreferrer"&gt;Beautify&lt;/a&gt; all make it easy to setup your style and format preferences in your project.&lt;br&gt;
Features like format on save and format on paste ensure that your code can look great as soon as you start writing it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; - Integrates ESLint into VS Code.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; - I use Prettier to format my code. I'll include basic formatting options directly in VS Code settings that are used if project specific settings aren't found.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Settings
&lt;/h2&gt;

&lt;p&gt;Here's a list of my current VS Code settings if you're interested in using them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"workbench.iconTheme"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"material-icon-theme"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"workbench.colorTheme"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Monokai++"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"material-icon-theme.activeIconPack"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"material-icon-theme.saturation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"explorer.compactFolders"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.largeFileOptimizations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.cursorWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.lineHeight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.letterSpacing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.fontWeight"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"normal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.fontSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.formatOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.formatOnPaste"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.minimap.enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"diffEditor.ignoreTrimWhitespace"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"[javascript]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esbenp.prettier-vscode"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"[html]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esbenp.prettier-vscode"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"window.zoomLevel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"window.newWindowDimensions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"offset"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"liveServer.settings.CustomBrowser"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"firefox"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"[json]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esbenp.prettier-vscode"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"prettier.jsxSingleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"prettier.singleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"prettier.bracketSpacing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"prettier.printWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"prettier.tabWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"markdown.preview.fontSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"files.trimTrailingWhitespace"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"telemetry.enableTelemetry"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"telemetry.enableCrashReporter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;In this article we took a look at one way to configure VS Code for web development. Although workflow and preferences will always be changing, setting up a solid foundation in your workspace can really help improve the dev experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/community/questions/best-monospace-code-fonts-for-developers" rel="noopener noreferrer"&gt;Monospace fonts - DIgital Ocean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/tonsky/FiraCode" rel="noopener noreferrer"&gt;Fira Code - GitHub&lt;/a&gt; - Free monospaced font containing ligatures for common programming multi-character combinations&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>learning</category>
      <category>vscode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript variables: Getting started</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Tue, 03 Nov 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/javascript-variables-getting-started-5543</link>
      <guid>https://forem.com/jordanholtdev/javascript-variables-getting-started-5543</guid>
      <description>&lt;p&gt;You can think of variables as containers of information. Variables allow a way of labeling data with a descriptive name. They are not values themselves, but they contain values and represent them with a name.&lt;/p&gt;

&lt;p&gt;You can assign different kinds of values to variables, such as strings, arrays and objects.&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;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;counter&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;names&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;Joe&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;Alice&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;Frank&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;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;operating&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Declaring a variable
&lt;/h2&gt;

&lt;p&gt;Variables are declared using one of three keywords in JavaScript &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. Prior to ECMAScript 2015 &lt;code&gt;var&lt;/code&gt; was used to declare all 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;var&lt;/span&gt; &lt;span class="nx"&gt;fruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstNames&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;Joe&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;Jessica&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;Alice&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many new programs will only use &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; but &lt;code&gt;var&lt;/code&gt; is still out there.&lt;/p&gt;

&lt;p&gt;Let's have a closer look at a variable declaration.&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;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, a variable called &lt;code&gt;userName&lt;/code&gt; has been declared using the &lt;code&gt;let&lt;/code&gt; keyword, it has been assigned a value of &lt;code&gt;Joe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5kihlmuc1hjpqae9mcjj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5kihlmuc1hjpqae9mcjj.jpg" alt="variable-declaration-marked" width="561" height="301"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; keyword declares a new variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;userName&lt;/code&gt; is the variable name, or identifier.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;=&lt;/code&gt; the assignment operator assigns the value to the variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Joe&lt;/code&gt; is the value that the variable was initialized with.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also use destructuring assignment syntax to create a variable and assign value from object literals.&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;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;mileage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;operatingStatus&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="c1"&gt;// creates a variable named size&lt;/span&gt;
&lt;span class="c1"&gt;// assigns size value equal to engine.size&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;engine&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="s2"&gt;`engine size: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: engine size: 600&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above we unpack the name and value of the engine objects &lt;code&gt;size&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Now that we've seen how easy it is to get started, let's have a closer look at naming JavaScript variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Naming variables
&lt;/h2&gt;

&lt;p&gt;When considering a name, it's important that it is relatively descriptive and easy to read. In contrast to variables in mathematics, variable names in JavaScript programs are usually choosen based on readability and descriptiveness .&lt;/p&gt;

&lt;p&gt;Camel casing is also a common convention used in JavaScript programs.&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;userSelectedItems&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;Variable names are called identifiers. Identifiers are sequences of characters that are used to identify a variable, function or property.&lt;/p&gt;

&lt;p&gt;JavaScript identifiers&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are case-sensitive&lt;/li&gt;
&lt;li&gt;Must start with a letter, &lt;code&gt;$&lt;/code&gt; or &lt;code&gt;_&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Can contain Unicode letters&lt;/li&gt;
&lt;li&gt;Can contain digits (0-9), but cannot start with a digit&lt;/li&gt;
&lt;li&gt;Can contain &lt;code&gt;$&lt;/code&gt; and &lt;code&gt;_&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These identifiers are all acceptable:&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;$one_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jane&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Status_Number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;_speed10&lt;/span&gt; &lt;span class="c1"&gt;// _underscore is sometimes used to indicate private vars&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use Unicode letters and Unicode escapes sequences.&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="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;u0636&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;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;exampleChar&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;u0E16&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Thai&lt;/span&gt;&lt;span class="dl"&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;exampleCharถ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Thai&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="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;u0636&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Ouput: [1, 2, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although the variable names above are allowed, you'll generally try and choose variable names that are descriptive and therefor easy to read. Conventions like camel casing are followed to help readability.&lt;/p&gt;

&lt;p&gt;These are good 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="c1"&gt;// these are good names&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userEmail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;joe@example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although variable names are case sensitive, don't create multiples that share the same name but have different casing.&lt;/p&gt;

&lt;p&gt;This would be considered bad practice 🚫&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 do this&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;exampleFruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;examplefruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variable names cannot use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords" rel="noopener noreferrer"&gt;reserved keywords&lt;/a&gt;. Watch out for keywords like &lt;code&gt;new&lt;/code&gt;, &lt;code&gt;with&lt;/code&gt;, &lt;code&gt;this&lt;/code&gt; these are reserved. You'll likely get a &lt;code&gt;SyntaxError&lt;/code&gt; if you attempt to use these.&lt;/p&gt;

&lt;p&gt;While that was a lot of information about naming variables, the overall goal should be creating variable names that are descriptive and easy to read. If you have a clear reason to steer away from common practice then try and be consistent in your choices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variable scope
&lt;/h2&gt;

&lt;p&gt;An important difference between JavaScript and other languages like Java, is that in JavaScript, blocks do not have scope, only functions have a scope. So if a variable is defined using &lt;code&gt;var&lt;/code&gt; in a compound statement (for example inside an &lt;code&gt;if&lt;/code&gt; control structure), it will be visible to the entire function. However, starting with ECMAScript 2015, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declarations allow you to create block-scoped variables. Let's have a closer look at this.&lt;/p&gt;

&lt;p&gt;If you declare a variable outside of any function, it is known as a &lt;em&gt;global&lt;/em&gt; variable, when you declare a variable inside of a function it is called a &lt;em&gt;local&lt;/em&gt; variable. Local variables are available within the function they are declared.&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;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="c1"&gt;// Global variable&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;example&lt;/span&gt;&lt;span class="p"&gt;()&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;speak&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// Local variable&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Global variables are properties of the global object. You can see this by opening a browser console and creating a global variable, then access the variable through the window object. The window object is the global object in the browser.&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;var&lt;/span&gt; &lt;span class="nx"&gt;globalNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&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;globalNum&lt;/span&gt; &lt;span class="c1"&gt;// Output: 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prior to ECMAScript 2015 and the &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords, JavaScript didn't have block statement scope. So a variable declared inside a block is local to the scope that the block is in.&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;example&lt;/span&gt;&lt;span class="p"&gt;()&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;speak&lt;/span&gt; &lt;span class="o"&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="k"&gt;if &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="kd"&gt;var&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;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;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Ouput: 5; no block scope&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using the &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; keywords to declare a variable, it will be block-scoped. That means it is only available in the scope of the containing block.&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;example&lt;/span&gt;&lt;span class="p"&gt;()&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;speak&lt;/span&gt; &lt;span class="o"&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="k"&gt;if &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="kd"&gt;let&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;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;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: ReferenceError: num is not defined&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;let&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; keyword allows you to reassign the variable to a different 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;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&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;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: red&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="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&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;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: blue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;let&lt;/code&gt; keyword declares block level variables. The declared variable is available from the block it's enclosed in as well as sub-blocks.&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="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;1&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;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&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;// Output: 2&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;// Output: 1&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also declare a variable without assigning it a value. In this case the variable will be initialized with a value of &lt;code&gt;undefined&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;pizza&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;pizza&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: undefined&lt;/span&gt;
&lt;span class="nx"&gt;pizza&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cheese&lt;/span&gt;&lt;span class="dl"&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;pizza&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Cheese&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;const&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt; allows you to declare variables whose values are not meant to change. The variable is available from the block its declared in.&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;myBirthday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1990-11-02&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A variable declared with the &lt;code&gt;const&lt;/code&gt; keyword cannot be reassigned. They are meaned to stay constant and attempting to reassign them will cause a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_const_assignment" rel="noopener noreferrer"&gt;&lt;code&gt;TypeError&lt;/code&gt;&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;fruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;// Output: TypeError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see a &lt;code&gt;TypeError&lt;/code&gt; like this in the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Uncaught TypeError: invalid assignment to const &lt;span class="s1"&gt;'fruit'&lt;/span&gt;
    fruit &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Banana'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       ^

TypeError: Assignment to constant variable.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;const&lt;/code&gt; variables must be assigned a value when first declared. If not declared with a value, it will result in a &lt;code&gt;SyntaxError&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;animals&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Ouput: SyntaxError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;Wow, that was a lot of information about JavaScript variables. But now you should have a pretty good understanding of JavaScript variables and how to use them. Remember that variables are not values themselves, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are block-scoped, watch out for reserved keywords and choose descriptive and easy to read names.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reference
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#Description" rel="noopener noreferrer"&gt;var - MDN&lt;/a&gt;&lt;/p&gt;

</description>
      <category>learning</category>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Gatsby: Creating custom Markdown components</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Fri, 30 Oct 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/gatsby-creating-custom-markdown-components-1h4o</link>
      <guid>https://forem.com/jordanholtdev/gatsby-creating-custom-markdown-components-1h4o</guid>
      <description>&lt;p&gt;If you're working with MDX in Gatsby, make sure to take advantage of custom components using &lt;code&gt;MDXProvider&lt;/code&gt;. This can give you the ability to apply your design system consistently across your content when you're using MDX.&lt;/p&gt;

&lt;p&gt;In this article we'll use custom components to replace the HTML that is rendered by Markdown. You can easily integrate libraries like &lt;code&gt;theme-UI&lt;/code&gt; or &lt;code&gt;Chakra-UI&lt;/code&gt; if you're using an existing design system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;In this example we'll be using the &lt;a href="https://www.gatsbyjs.com/starters/gatsbyjs/gatsby-starter-default/" rel="noopener noreferrer"&gt;gatsby-starter-default&lt;/a&gt; project. This assumes you already have the Gatsby CLI installed on your system. If not, you can &lt;a href="https://www.gatsbyjs.com/docs/quick-start/#use-the-gatsby-cli" rel="noopener noreferrer"&gt;read about installing it here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's go ahead and install the starter project. I'm naming the project folder "gatsby-custom-mdx-components", but you can name it anything you want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; gatsby new gatsby-custom-mdx-components https://github.com/gatsbyjs/gatsby-starter-default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can navigate to our project directory and list the contents. Then we'll open up a text-editor (I'm using VS Code) and have a closer look at the package.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;gatsby-custom-mdx-components &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; code &lt;span class="nb"&gt;.&lt;/span&gt;

d----          2020-10-30  8:22 AM                node_modules
d----          2020-10-30  8:21 AM                src
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM           1043 .gitignore
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM             49 .prettierignore
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM             50 .prettierrc
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM            171 gatsby-browser.js
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM           1111 gatsby-config.js
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM            165 gatsby-node.js
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM            187 gatsby-ssr.js
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM            689 LICENSE
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM           1308 package.json
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM         777362 package-lock.json
&lt;span class="nt"&gt;-a---&lt;/span&gt;          2020-10-30  8:21 AM           5670 README.md

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

&lt;/div&gt;



&lt;p&gt;The starter is a basic Gatsby project. It comes with a some of the bare-bones plugins like transformer-sharp and React Helmet for SEO but no way to handle MDX out of the box. We'll be using the &lt;a href="https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/?=gatsby-plugin-mdx" rel="noopener noreferrer"&gt;gatsby-plugin-mdx&lt;/a&gt; to programmatically create the MDX pages. This plugin relies on &lt;a href="https://www.npmjs.com/package/@mdx-js/mdx" rel="noopener noreferrer"&gt;@mdx-js/mdx&lt;/a&gt; to parse MDX to JSX and &lt;a href="https://www.npmjs.com/package/@mdx-js/react" rel="noopener noreferrer"&gt;@mdx-js/react&lt;/a&gt; to implement MDX for React.&lt;/p&gt;

&lt;p&gt;Let's go ahead and install these packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can confirm the install by checking the package.json, you should see the 3 packages installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "dependencies": {
    "@mdx-js/mdx": "^1.6.19",
    "@mdx-js/react": "^1.6.19",
    "gatsby": "^2.24.91",
    "gatsby-image": "^2.4.21",
    "gatsby-plugin-manifest": "^2.4.37",
    "gatsby-plugin-mdx": "^1.2.52",
    "gatsby-plugin-offline": "^3.2.38",
    "gatsby-plugin-react-helmet": "^3.3.14",
    "gatsby-plugin-sharp": "^2.6.43",
    "gatsby-source-filesystem": "^2.3.37",
    "gatsby-transformer-sharp": "^2.5.20",
    "prop-types": "^15.7.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-helmet": "^6.1.0"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring the plugin
&lt;/h2&gt;

&lt;p&gt;Now that &lt;code&gt;gatsby-plugin-mdx&lt;/code&gt; is installed in the project, we'll need to configure the plugin.&lt;/p&gt;

&lt;p&gt;We'll need to specificy the location of local MDX files that will be processed. We can do this by specifiying the sources in the &lt;code&gt;gatsby-source-filesystem&lt;/code&gt; plugin, found in the &lt;code&gt;gatsby-config.js&lt;/code&gt; file. We'll also need to add &lt;code&gt;gatsby-plugin-mdx&lt;/code&gt; to the list of plugins in the config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;module.exports &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  plugins: &lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
      resolve: &lt;span class="sb"&gt;`&lt;/span&gt;gatsby-source-filesystem&lt;span class="sb"&gt;`&lt;/span&gt;,
      options: &lt;span class="o"&gt;{&lt;/span&gt;
        name: &lt;span class="sb"&gt;`&lt;/span&gt;posts&lt;span class="sb"&gt;`&lt;/span&gt;,
        path: &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;__dirname&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/src/pages/&lt;span class="sb"&gt;`&lt;/span&gt;,
                name: &lt;span class="sb"&gt;`&lt;/span&gt;pages&lt;span class="sb"&gt;`&lt;/span&gt;,
      &lt;span class="o"&gt;}&lt;/span&gt;,
    &lt;span class="o"&gt;}&lt;/span&gt;,
    &lt;span class="sb"&gt;`&lt;/span&gt;gatsby-plugin-mdx&lt;span class="sb"&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;Now if we create an MDX file in the pages directory, &lt;code&gt;gatsby-plugin-mdx&lt;/code&gt; will parse the file. Let's go ahead and create a file called &lt;code&gt;test.mdx&lt;/code&gt; in the pages directory, and add a bit of markdown to the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Using MDX with Gatsby&lt;/span&gt;

&lt;span class="gs"&gt;**This**&lt;/span&gt; is an example

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Learn more about MDX here&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://mdxjs.com/getting-started/gatsby&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Back home&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&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 should now be able to view the page by navigating to "/test". It should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/mdx-basic-components.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/mdx-basic-components.jpg" alt="Basic MDX Page" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! Now we can create pages using MDX but we still need to ability to use custom components to replace the HTML elements that the Markdown is rendering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom components
&lt;/h2&gt;

&lt;p&gt;Now that we are able to programmatically create pages with MDX the next step is providing the Markdown with custom components to use. Let's go ahead and create a file call &lt;code&gt;MDXComponents.js&lt;/code&gt; in the components directory. This is where we'll create our custom components.&lt;/p&gt;

&lt;p&gt;Let's add a couple of basic components.&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;// src/components/MDXComponents.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gatsby&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomHeading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;color&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="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;href&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isInternalLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;href&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="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&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="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isInternalLink&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&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;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&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;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;MDXComponents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CustomHeading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CustomLink&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MDXComponents&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, we created two custom components, &lt;code&gt;Heading1&lt;/code&gt; and &lt;code&gt;CustomLink&lt;/code&gt;. You'll notice in the CustomLink component, that we're rendering Gatsby Link when the link is internal and a regular &lt;code&gt;a&lt;/code&gt; element when it's external. You can easily use third-party libraries like &lt;code&gt;theme-ui&lt;/code&gt; or &lt;code&gt;Charka-UI&lt;/code&gt; when writing your custom components.&lt;/p&gt;

&lt;p&gt;Once these components are defined we then assign them to an object called &lt;code&gt;MDXComponents&lt;/code&gt; that we will export to use globally with the &lt;code&gt;MDXProvider&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's a full list of components that can be customized using the MDXProvider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;p&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h4&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h5&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;h6&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;thematicBreak&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;blockquote&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ul&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ol&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;li&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;table&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;td/th&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pre&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;code&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;em&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;strong&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;delete&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;inlineCode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;a&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;img&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  MDXProvider
&lt;/h2&gt;

&lt;p&gt;If we look at the test page again, you'll notice that our custom components haven't been applied to the Markdown. We do this by passing the custom components to &lt;code&gt;MDXProvider&lt;/code&gt; which will make them globally available to MDX that is wrapped by &lt;code&gt;MDXProvider&lt;/code&gt;. In this example we'll wrap the entire app.&lt;/p&gt;

&lt;p&gt;To do this open up &lt;code&gt;gatsby-browser.js&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MDXProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@mdx-js/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MDXComponents&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/components/MDXComponents&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapRootElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;element&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MDXProvider&lt;/span&gt; &lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;MDXComponents&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;element&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/MDXProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;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 import React, MDXProvider and our custom components. The entire app is then wrapped with &lt;code&gt;MDXProvider&lt;/code&gt; and the custom components are passed in.&lt;/p&gt;

&lt;p&gt;Now if we head back to the test page you should see that the custom components have been rendered. We can inspect the links and now see that the logic in the &lt;code&gt;CustomLink&lt;/code&gt; component has been applied to the elements, the internal links are Gatsby Links and the external links are &lt;code&gt;a&lt;/code&gt; elements each with their own styles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/mdx-custom-components.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/mdx-custom-components.jpg" alt="Custom MDX components Page" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;Using MDX in your projects can be a great experience for both developers and users. By using custom components via &lt;code&gt;MDXProvider&lt;/code&gt; you can help streamline your content workflow and keep your design system consistent throughout your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.com/docs/mdx/customizing-components/" rel="noopener noreferrer"&gt;Customizing Markdown Components - Gatsby&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.com/docs/mdx/customizing-components/" rel="noopener noreferrer"&gt;Gatsby - MDXJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.gatsbyjs.com/docs/mdx/customizing-components/" rel="noopener noreferrer"&gt;gatsby-plugin-mdx - Gatsby&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>learning</category>
      <category>gatsby</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Built-in form validation</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Fri, 23 Oct 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/built-in-form-validation-51bk</link>
      <guid>https://forem.com/jordanholtdev/built-in-form-validation-51bk</guid>
      <description>&lt;p&gt;There are many ways to validate user data when working with forms on the client-side. You can write custom JavaScript to do this, or use one of the many 3rd party libraries that are available like &lt;a href="https://formik.org/" rel="noopener noreferrer"&gt;Formik&lt;/a&gt; for React. However, one of the easiest ways is to take advantage of the built-in validation in the HTML5 specs.&lt;/p&gt;

&lt;p&gt;Let’s create a basic newsletter sign up form as an example. You can see the final &lt;a href="https://gist.github.com/jordanholtdev/61c82857b88f366f3678b51b1a28eb51" rel="noopener noreferrer"&gt;form here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One of the first ways to implement validation is by using the input element &lt;a href="https://html.spec.whatwg.org/multipage/input.html#attr-input-type" rel="noopener noreferrer"&gt;&lt;code&gt;type&lt;/code&gt;&lt;/a&gt; attribute. When we include the &lt;code&gt;type&lt;/code&gt; attribute some basic constraint validation and in some cases a &lt;a href="https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm" rel="noopener noreferrer"&gt;value sanitization algorithm&lt;/a&gt; will be applied to the value of the form control.&lt;/p&gt;

&lt;p&gt;For example, if we set the &lt;code&gt;type&lt;/code&gt; attribute to “email”, the value attribute must be a &lt;a href="https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address" rel="noopener noreferrer"&gt;valid email-address&lt;/a&gt;. If the value is not a valid email address then the browser will generate an error message for the user.&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;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email:
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/label&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;However, the &lt;code&gt;type="email"&lt;/code&gt; attribute in this case would still consider a value like “hello@b” as valid because it accepts &lt;a href="https://en.wikipedia.org/wiki/Intranet" rel="noopener noreferrer"&gt;intranet&lt;/a&gt; email addresses. So we could further constrain the validation by using the &lt;a href="https://html.spec.whatwg.org/multipage/input.html#attr-input-pattern" rel="noopener noreferrer"&gt;&lt;code&gt;pattern&lt;/code&gt;&lt;/a&gt; attribute. The &lt;code&gt;pattern&lt;/code&gt; attribute accepts a regular expression.&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;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email(required):
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
      &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;
      &lt;span class="na"&gt;pattern=&lt;/span&gt;&lt;span class="s"&gt;"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$"&lt;/span&gt;
      &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"example@example.com"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  An email address uses the following format: example@example.com
&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’ll notice that we also added a &lt;a href="https://html.spec.whatwg.org/multipage/input.html#attr-input-title" rel="noopener noreferrer"&gt;&lt;code&gt;title&lt;/code&gt;&lt;/a&gt; attribute that is used to describe the &lt;code&gt;pattern&lt;/code&gt;. Most browsers will display the title as a tooltip when hovered over the element, and will inlcude the title in the error message when the value does not match the pattern. However this isn’t always the case and it’s good practice to display that information in other ways to assist the user.&lt;/p&gt;

&lt;p&gt;Another common attribute when using built-in validation is &lt;a href="https://html.spec.whatwg.org/multipage/input.html#attr-input-required" rel="noopener noreferrer"&gt;&lt;code&gt;required&lt;/code&gt;&lt;/a&gt;. When this attribute is included on an input element, the field will mandatory and an error message will be displayed if the form is submitted and the input is empty.&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;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email(required):
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
      &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;
      &lt;span class="na"&gt;pattern=&lt;/span&gt;&lt;span class="s"&gt;"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$"&lt;/span&gt;
      &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"example@example.com"&lt;/span&gt;
      &lt;span class="na"&gt;required&lt;/span&gt;
      &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"john@example.com"&lt;/span&gt;
      &lt;span class="na"&gt;aria-required=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  An email address uses the following format: example@example.com
&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;Again, it’s a good idea to convey this visually to the user. In this case simply by adding “(required)” to the label. The aria-required attribute is set to true which is mostly redundant as current browsers often set this value to &lt;code&gt;true&lt;/code&gt; when the &lt;code&gt;required&lt;/code&gt; attribute is present. But to support more browsers it’s been included in this example. We also added a &lt;code&gt;placeholder&lt;/code&gt; attribute to provide a hint to the user at the intended use of the data entry.&lt;/p&gt;

&lt;p&gt;Let’s go ahead and add a field that collects the users name. This will be a required field that accepts the users name. We’ll add a length constraint because most names are going to contain only a small number of letters.&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;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Name(required):
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
      &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;
      &lt;span class="na"&gt;pattern=&lt;/span&gt;&lt;span class="s"&gt;"^[a-zA-z]+[a-zA-z]{1,}"&lt;/span&gt;
      &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"Name contains the characters a-z and is under 100 characters in lenth"&lt;/span&gt;
      &lt;span class="na"&gt;required&lt;/span&gt;
      &lt;span class="na"&gt;aria-required=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
      &lt;span class="na"&gt;maxlength=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt;
      &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/label&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;Again, we’ve added the a &lt;code&gt;pattern&lt;/code&gt; to this input element so only names containing the characters A-Z in upper of lower case will be valid. Be careful when writing your regular expressions as it’s easy to exclude people. For example if there are &lt;a href="https://en.wikipedia.org/wiki/Diacritic" rel="noopener noreferrer"&gt;diacritic&lt;/a&gt; characters in a name the above &lt;code&gt;pattern&lt;/code&gt; would not accept them as valid.&lt;/p&gt;

&lt;p&gt;Now we could add a few styles to the form elements and take advantage of some of the &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Forms/UI_pseudo-classes" rel="noopener noreferrer"&gt;UI pseudo-classes&lt;/a&gt; that are set when we use certain validation attributes. For example we can the &lt;code&gt;:invalid&lt;/code&gt; pseudo-class to style the input elements when they do not meet the validation requirements.&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;form&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;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1em&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;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;320px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="o"&gt;&amp;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;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25&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;600&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;1.5rem&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;26&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;44&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;label&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="nl"&gt;padding-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&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;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;500&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;left&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;1.25&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="nb"&gt;block&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;0px&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;solid&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="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;226&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;232&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;240&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"text"&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt;
&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"email"&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt;
&lt;span class="nt"&gt;fieldset&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="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="m"&gt;#333&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="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="nl"&gt;padding-left&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="nl"&gt;padding-right&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="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.25rem&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;solid&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="nb"&gt;inherit&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="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:focus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&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;border-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;49&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;130&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;206&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&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;49&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;130&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;206&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:invalid&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="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;255&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="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.301&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nd"&gt;:valid&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="n"&gt;rgba&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="m"&gt;128&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="m"&gt;0.301&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;form&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;button&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;1rem&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;2.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&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="nb"&gt;rgb&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="m"&gt;151&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;149&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;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&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="nl"&gt;padding-left&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="nl"&gt;padding-right&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="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600&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="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;form&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="o"&gt;&amp;gt;&lt;/span&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;background-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;44&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;122&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;123&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;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;With just a few simple attributes we can easily start to implement client-side validation when working with forms. While this won’t be as flexible as using JavaScript it can provide a simple solution. Remember that you should always be using thorough server-side validation and sanitization in addition to client-side validation.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>html</category>
      <category>learning</category>
    </item>
    <item>
      <title>Client expectations and onboarding for freelancers</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Tue, 13 Oct 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/client-expectations-and-onboarding-for-freelancers-1gi1</link>
      <guid>https://forem.com/jordanholtdev/client-expectations-and-onboarding-for-freelancers-1gi1</guid>
      <description>&lt;p&gt;Creating a clear process for onboarding new clients is an important step when freelancing. From the first interaction with a new client it’s important to define the relationship and expectations. I freelanced in the film &amp;amp; television industry for almost a decade before I transitioned into web development where I continue to freelance. I was project manager on several feature length documentaries, films, commercials and live events. My experience taught me the importance aligning expectations and clear communication throughout the life cycle of a project and continue to serve me well as a developer.&lt;/p&gt;

&lt;p&gt;Here are a few of things I learned about taking on new clients and expectations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every journey is going to look different
&lt;/h2&gt;

&lt;p&gt;The process around taking on new projects or clients is always evolving and no two projects will be the same. It’s important to stay flexible (within reason) to other methods and processes when interacting with new clients. Try and be empathetic and realize that the client is also taking a risk with you, help them feel secure by having a clear process from the moment you first interact. When there is no process in place, expectations cannot be aligned and a project can quickly get into trouble. So what does this process look like?&lt;/p&gt;

&lt;p&gt;The process will vary based on your business and the type of clients and projects you work with. Regardless of how it takes shape the goal is to have a clear process in place from the initial contact of a client to when you agree to move forward with a project.&lt;/p&gt;

&lt;p&gt;Here is an example of an onboarding process I use. This process will evolve based on you preferences and the scope of your work but it often follows this pattern.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initial contact&lt;/strong&gt; - A client has found me from one of several possible channels (i.e link at the bottom of a site you built, referral, promotion), and then reaches out. This is usually an email, but it could be a phone call or other method of contact you’ve setup. During this step the client usually gives me a bit a information about the project. At this stage it’s usually vague but the requirements are sometimes detailed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response &amp;amp; basic queries&lt;/strong&gt; - When I find the time, I’ll respond to the client. During this step I provide a list of questions to the client to learn more about the project requirements. These are basic questions that I ask for the majority of projects I work on. Depending on your work you might even automate this by having a form that clients are directed to after the initial contact.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review &amp;amp; schedule meeting&lt;/strong&gt; - Once the initial questions are answered, I take some time to sit with them and make notes. Once I’ve gone through the answers and done some basic research on the clients business, I’ll request to schedule a brief meeting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;First meeting&lt;/strong&gt; - This meeting is meant to be a discussion and is exploratory in nature. I meet with the client to get to know each other, learn about the project and determine if it’s a good fit. A 30 or 40 minute call or video meeting is usually enough time. The goals of this step are to clarify any questions I have and to get to know the client. Red flags at this point are not a good sign.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Statement of work&lt;/strong&gt; - At this point, I’ll usually have enough information to decide if the project / client are a good fit for me. If I’m still not clear on the project at this point it could be a bad sign. But if things are clear and I feel it’s a good fit, then I start working on a statement of work document. What you actually send them will vary based on the nature and scale of the work and your personal preference, it could be a simple one page document sent in the body of an email or a larger document or series of documents but you should have the basics covered including deliverables, timelines, specific responsibilities and cost. I go into more detail below about what to include.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signing and payment&lt;/strong&gt; - When the client and I are synced up and in agreement regarding the scope of work and requirements then we agree to proceed. I have the client sign the statement of work and send the payment. Depending on your industry and the project this could be complete payment upfront but in my experience splits like 50% upfront / 50% upon completion or 50% / 25% / 25% are also common. The takeaway is that I’m not starting work without money in the bank.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client Requirements&lt;/strong&gt; - Generally there are a number of things that I’ll need from the client before I can get started. This could be photos or copy for a landing page, or API credentials or numerous other things that could prevent the project from moving forward. I usually send a brief checklist of items/tasks they need to complete before I get to work.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Get it in writing
&lt;/h2&gt;

&lt;p&gt;It’s often appealling to keep things casual, especially when it’s a smaller project or if you’re just starting out but this is a mistake. Although people generally have good intentions, expectations can be the cause of a lot of headaches. Laying out requirements and important details like budget details, scope and payment schedule on paper will help avoid misunderstandings, align expectations and reduce any emotion that might occur if you or the client feel slighted. You have an agreement in writing that you can refer to.&lt;/p&gt;

&lt;p&gt;Proposals, work agreements, statement of work and other documents can be used when working out the details of a new project. However, if you’re just getting started freelancing I suggest you keep things as simple as possible. A single document is often all that’s needed for smaller projects. The main goal is to align the clients expectations with yours and to agree in as much detail as possible the work requirements, budget and timeline.&lt;/p&gt;

&lt;p&gt;For most of the projects I work on I use a single document called a statement of work. The &lt;a href="https://en.wikipedia.org/wiki/Statement_of_work" rel="noopener noreferrer"&gt;statement of work document(SOW)&lt;/a&gt; was traditionally used as a document that accompanied a request for proposal (RFP) and detailed the work requirements laid out in the RFP. However the SOW format serves freelancers well as a document that can outline the important details of a project. Modified SOW documents are commonly used in the freelance world and are often used as binding contracts. Paperwork can be intimidating to some clients, so I find using a modified statement of work document that is used as an agreement works well for most of my use cases.&lt;/p&gt;

&lt;p&gt;There are many different SOW templates out there, all of which include different elements. Some elements are obviously useful while others will only be beneficial for certain projects, with experience you’ll learn what to include. Here’s a few things I usually include in my statement of work document:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Introduction&lt;/strong&gt; - This is going to include a general description of what the project is about and your understanding of the clients business and what will be gained by completing this project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scope of work / Responsibilities&lt;/strong&gt; - This is a brief summary of your expectations regarding the scope and responsibilities for yourself and the client. This is usually an overview, while a more detailed and technical breakdown is often included in a work requirements section.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exlusions&lt;/strong&gt; - It’s a good idea to also include &lt;strong&gt;what is exluded&lt;/strong&gt; from your responsibilities. This is optional and it’s generally assumed that anything not included in the scope or work requirements would be exluded, it doesn’t hurt to have more detail. With experience you’ll start to develop an instinct for to include here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeline&lt;/strong&gt; - This section will define how long the project will take to complete. It’s also common to indicate what happens in the case of delays. Depending on the size of the project you could incorporate the schedule and milestones into this section or have a separate section.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Work Requirements/Deliverables&lt;/strong&gt; - This is a section where you can get detailed about the work requirements. In some cases it’s best to summarize these requirements for each stage of a project. &lt;em&gt;Design Phase&lt;/em&gt; Build Phase * Handoff Phase&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost / Payment Schedule&lt;/strong&gt; - This is the section where you detail how much it’s going to cost. Make sure to include when payments due dates, down payments and some detail about the process around late payments and kill fees ect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use this as a starting point and add or remove sections based on your needs. This document is going to change over time but the goal will remain the same, it describes the the work requirements and aligns expectations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Communication is key
&lt;/h2&gt;

&lt;p&gt;Open and ongoing communication is key when working in a team and even more important when working with new clients. Details like the frequency and method of meetings, dealing with documents, communication preferences and so on should be discussed and agreed upon when a project begins.&lt;/p&gt;

&lt;p&gt;A well thought out communication process will help keep the project on track and avoid common issues. Here are a few of the common issues that inevitably creep up throughout the life cycle of a project:&lt;/p&gt;

&lt;h4&gt;
  
  
  Reevaluate scope
&lt;/h4&gt;

&lt;p&gt;Inevitably the scope of the work you’ve agreed on will start growing, aka scope creep. There are a number of reasons for this but most commonly this is due to misunderstanding the project requirements and client expectations. Early on in the project it’s important to reiterate scope and go over the process with the client.&lt;/p&gt;

&lt;h4&gt;
  
  
  Schedule regular discussion for feedback
&lt;/h4&gt;

&lt;p&gt;From the very beginning of a project ensure that there are regularly scheduled meetings for feedback. Call these meetings whatever you want to but there should be frequent and consistent and allow for you and the client to openly provide feedback on the project. Ideally these meetings take place in person, or on a video or voice call so that you the interaction is more natural. This gives an opportunity for those involved to voice concerns or suggestions without having to reaching out specifically about it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Regularly evaluate the project status
&lt;/h4&gt;

&lt;p&gt;To keep the project on track it’s important to keep track of the project status. Usually this is a document that will be updated with project information such as budget, obstacles, accomplishments and next steps. Ideally you’ll go over this document before you start any work and review it regularly in meetings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Budget&lt;/li&gt;
&lt;li&gt;Project obstacles&lt;/li&gt;
&lt;li&gt;Accomplishments&lt;/li&gt;
&lt;li&gt;Next steps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To avoid these issues, it’s helpful to have a communication strategy in place at the beginning of a project. Again, the simpler the better and I find that a single document serves my purposes well. Here are a couple of things I like to include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project Team Directory - A simple list of all the team members involved in the project, their role and contact information.&lt;/li&gt;
&lt;li&gt;Contact Preferences - At the minimum you should agree on preferred methods of contact. You want to set some boundaries about when and how contact will take place. For example, don’t call me in the middle of the night with unless it’s an emergency and agree what constitutes an emergency.&lt;/li&gt;
&lt;li&gt;Communication Matrix - Fancy term for a list of the meetings, their goals and the method and frequency of the meetings. Below is an example of how this could look:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Goal&lt;/th&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Frequency&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Kickoff&lt;/td&gt;
&lt;td&gt;Initial project meeting. Introduce the project and review the requirements&lt;/td&gt;
&lt;td&gt;Conference call - Zoom&lt;/td&gt;
&lt;td&gt;Once&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Project Team Meetings&lt;/td&gt;
&lt;td&gt;Review status of project&lt;/td&gt;
&lt;td&gt;Conference call - Zoom&lt;/td&gt;
&lt;td&gt;Weekly. Mondays @ 10am&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Project Status&lt;/td&gt;
&lt;td&gt;Report of the status of project, milestones and issues&lt;/td&gt;
&lt;td&gt;Email&lt;/td&gt;
&lt;td&gt;Monthly&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Documents - How will project related documents be handled? Basecamp, Trello, Asana, Google Docs? Determine how documents will be stored and how to handle revisions etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Remember you’re communicating with other humans
&lt;/h2&gt;

&lt;p&gt;I often hear the phrase “this project has many moving parts” and I usually chuckle because those parts are generally other humans. We all have lives outside of a project, we have families and other obligations that are important to us. Determining healthy boundaries around communication early on in a project is essential to its overall success. Panicked phone calls in the middle of the night are an easy way to ruin a working relationship and can easily be avoided by having a process in place.&lt;/p&gt;

&lt;p&gt;It’s possible that a client is a new business owner and still discovering their own process, and the ability to recognize this can help build meaningful relationships in your career. Remember that people have lives outside of the projects they work on.&lt;/p&gt;

&lt;p&gt;Here are a few things suggestions that I find helpful when working with new clients:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Have some empathy for the clients&lt;/strong&gt;. If you’re having a difficult time with a client you can use it as an exercise in patience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don’t ever put up with a tyrant&lt;/strong&gt;. Coming from film and television I can tell you countless stories of big egos and bad behaviour, but it’s not isolated to that industry. Don’t ever put up with yelling, rudeness or any other poor behaviour.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practice active listening with your client&lt;/strong&gt;. Sometimes we become frustrated just because we feel we’re not being heard. Working with new clients creates a great opportunity to learn how to listen and recognize when others aren’t listening to you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;People have a big impact on the success of a project&lt;/strong&gt;. Psychological safety is an important part of creating an environment of success. A hostile, judgmental or otherwise negative environment is a recipe for disaster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Share with your clients&lt;/strong&gt;. Clients are taking a risk when invest in you. One way to make them feel their investment is safe is to openly share with them. Share your work, your though process and approaches regularly and don’t keep things tightly controlled or hidden from view.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;Freelancing as a developer can be a rewarding experience if you have a clear process for onboarding and communication in place from the onset of a project. With experience you’ll start to form a process that works best for you. The process doesn’t need to be overly formal or have an overwhelming number of documents, but there needs to be enough detail to avoid common issues. The more you’re able to align expectations the more likely you are to successfully complete a project and develop lasting, meaningful relationships with clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="http://www.lexwerks.com/article/project-management-is-people-management/" rel="noopener noreferrer"&gt;Project Management is People Management - Jason Miller&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://www.projectmanagementdocs.com/" rel="noopener noreferrer"&gt;Project Management Docs - Resource&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>career</category>
      <category>freelance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Getting started with forms</title>
      <dc:creator>Jordan Holt</dc:creator>
      <pubDate>Fri, 09 Oct 2020 00:00:00 +0000</pubDate>
      <link>https://forem.com/jordanholtdev/getting-started-with-forms-2lnn</link>
      <guid>https://forem.com/jordanholtdev/getting-started-with-forms-2lnn</guid>
      <description>&lt;p&gt;Forms are one of the most common ways that users interact with a site or app. From a simple newsletter subscription to a complex multi-line shipping form, they are found on almost every site and app on the web. In this article we’ll build a basic form that introduces some commonly used concepts and elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an HTML form?
&lt;/h2&gt;

&lt;p&gt;A form is a component of a web page that a user can interact with, and provide data to, which will then be submitted and sent to a server for processing (e.g. submitting an email address to subscribe to a newsletter) or in some cases used client-side (e.g. update the UI to add or remove elements).&lt;/p&gt;

&lt;p&gt;Forms have various control elements that users can interact with such as buttons, text inputs, range controls and checkboxes. We’ll have a closer look at those elements shortly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The steps to creating a form
&lt;/h2&gt;

&lt;p&gt;Creating a form can generally be broken down into a few steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Designing the form&lt;/li&gt;
&lt;li&gt;Creating the user interface&lt;/li&gt;
&lt;li&gt;Creating the server-side or client-side code to process the form data&lt;/li&gt;
&lt;li&gt;Configuring the form to communicate with a server.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Form design and server-side form processing are beyond the scope of this article and deserve some thorough attention. If you’re interested in reading more about form design check out these articles:&lt;/p&gt;

&lt;p&gt;Form design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;UXMatters has several great resources on forms &lt;a href="https://www.uxmatters.com/mt/archives/2012/05/7-basic-best-practices-for-buttons.php" rel="noopener noreferrer"&gt;like this article on best practices&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;UX Planet is a blog about user experience and has a good article on the &lt;a href="https://uxplanet.org/designing-more-efficient-forms-structure-inputs-labels-and-actions-e3a47007114f" rel="noopener noreferrer"&gt;basics of efficient forms&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Server-side form processing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MDN has a great article about &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/forms" rel="noopener noreferrer"&gt;processing HTML form data using Node.js and Express&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Defining the data
&lt;/h2&gt;

&lt;p&gt;In this article we’ll be creating a form for ordering a hamburger. Let’s quickly define what data this form needs to collect.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;User information&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Customer name&lt;/li&gt;
&lt;li&gt; Telephone number&lt;/li&gt;
&lt;li&gt; Email address&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Hamburger type&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Beef&lt;/li&gt;
&lt;li&gt; Veggie&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

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

&lt;ul&gt;
&lt;li&gt; Cheese&lt;/li&gt;
&lt;li&gt; Ketchup&lt;/li&gt;
&lt;li&gt; Mustard&lt;/li&gt;
&lt;li&gt; Pickle&lt;/li&gt;
&lt;li&gt; Onion &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Delivery instructions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Any special comments for delivery (e.g. enter through side-door)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Now that we have a better idea of what data the form needs to collect, let’s go ahead and start building the form.&lt;/p&gt;

&lt;h2&gt;
  
  
  The form element
&lt;/h2&gt;

&lt;p&gt;The first thing we do when we create any form is to use the &lt;a href="https://html.spec.whatwg.org/multipage/forms.html#the-form-element" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;&lt;/a&gt; element. All of the form controls will then be placed inside.&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example..com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The form element is a container element that defines our form. While the attributes are optional, you’ll find these are very common for web forms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-action" rel="noopener noreferrer"&gt;action&lt;/a&gt;&lt;/strong&gt; - The form action takes a URL that defines the location where the form data will be sent for processing. In this case when a user submits this form the data will be sent to &lt;code&gt;https://tasty.hamburgers.example.com/order&lt;/code&gt; for processing on the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method" rel="noopener noreferrer"&gt;method&lt;/a&gt;&lt;/strong&gt; - Forms interact with servers in a few ways, most commonly is the HTTP GET and POST methods. This attribute defines which method the form uses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-enctype" rel="noopener noreferrer"&gt;enctype&lt;/a&gt;&lt;/strong&gt; - Defines the type of content that is used when submitting form data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we can start adding the form controls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Form controls
&lt;/h2&gt;

&lt;p&gt;The form controls will be contained inside the form element. Let’s start by adding an input that will collect the users name.&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside of a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; element we added our first form control, a label and an input to collect the users name. Inputs are the most common type of form control. You’ll notice that the label and input is contained inside a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; element. It’s very common to see forms that are structured using list elements such as &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; but in this article the form controls will be contained in &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; elements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/forms.html#the-label-element" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; - The label element represents a caption for the form control, in this case an &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;. In this example the form control (the &lt;code&gt;&amp;lt;input&lt;/code&gt;) is directly inside the label element, however you’ll often see them seperated like this:
&lt;/li&gt;
&lt;/ul&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;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;required&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;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the control is not directly inside the label, you need to use the attribute and a corresponding on the control. When users click / activate the label, the form control will be activated as if the user clicked on it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/input.html#the-input-element" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; - The input accepts data from the user. It accepts a huge number of data types and attributes and is fairly complex HTML element because of the countless combinations. Here are the attributes we are currently using in our example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-name" rel="noopener noreferrer"&gt;name&lt;/a&gt; - For every form control that is submitted, we need to give a name to the data. When a user submits the form to our server, the server will expect to receive that data in this case as parameters in a HTTP POST body. In our example the “custname” represents a parameter that the server is expecting.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://html.spec.whatwg.org/multipage/input.html#attr-input-type" rel="noopener noreferrer"&gt;type&lt;/a&gt; - The type attribute defines and controls the data type of the input element. In our example we are using the keyword &lt;a href="https://html.spec.whatwg.org/multipage/input.html#text-(type=text)-state-and-search-state-(type=search)" rel="noopener noreferrer"&gt;“text”&lt;/a&gt; whose data type is “text with no line breaks”.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://html.spec.whatwg.org/multipage/input.html#attr-input-required" rel="noopener noreferrer"&gt;required&lt;/a&gt; - This is a constraint attribute that is used in simple &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation" rel="noopener noreferrer"&gt;client-side validation&lt;/a&gt;. When required is used, the user will be notified when attempting to submit the form without the corrosponding input fields completed.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let’s finish off the customer information controls by adding the telephone and email fields.&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Telephone: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custtel"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custemail"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Grouping form controls
&lt;/h2&gt;

&lt;p&gt;Let’s add the ability to choose the hamburger type to our form. There are two types of hamburgers patties available, “Beef” &amp;amp; “Veggie”. The most intuitive way for a user to select the option is by using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio" rel="noopener noreferrer"&gt;radio buttons&lt;/a&gt;. Radio buttons also use the input element and are often grouped together.&lt;/p&gt;

&lt;p&gt;To select a radio button, the input attribute &lt;code&gt;type&lt;/code&gt; must be set to “radio”. For the radio buttons to work as a group they must share a common &lt;code&gt;name&lt;/code&gt; attribute, in this case the attribute has a value of “patty”.&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Telephone: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custtel"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custemail"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Hamburger patty&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Beef &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Veggie &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/form-elements.html#the-fieldset-element" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;fieldset&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; - This element is used when grouping a set of form controls together. It usually contains a caption that is supplied by the &lt;code&gt;&amp;lt;legend&amp;gt;&lt;/code&gt; element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let’s go ahead and add the ability for a user to pick the hamburger toppings. For this we will use the input type &lt;a href="https://html.spec.whatwg.org/multipage/input.html#checkbox-state-(type=checkbox)" rel="noopener noreferrer"&gt;“checkbox”&lt;/a&gt; since people will usually want more than one topping on thier burgers. Again we will give these controls a shared name attribute and contain them inside the &lt;code&gt;&amp;lt;fieldset&amp;gt;&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Telephone: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custtel"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custemail"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Hamburger patty&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Beef &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Veggie &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Toppings&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Cheese &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Ketchup &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Mustard &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Pickle &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Onion &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add a text area
&lt;/h2&gt;

&lt;p&gt;A common part of a form for deliveries is a special instructions text area. This input allows users to add a small amount of instructions for the delivery. Let’s go ahead and add one to this form using the &lt;a href="https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;&lt;/a&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Telephone: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custtel"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custemail"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Hamburger patty&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Beef &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Veggie &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Toppings&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Cheese &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Ketchup &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Mustard &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Pickle &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Onion &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Special instructions:
      &lt;span class="nt"&gt;&amp;lt;textarea&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"comments"&lt;/span&gt; &lt;span class="na"&gt;maxlength=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll notice we added a &lt;a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-maxlength" rel="noopener noreferrer"&gt;&lt;code&gt;maxlength&lt;/code&gt;&lt;/a&gt; attribute to the text area. This was done to prevent really long special instructions and is another example of a constraint attribute and client-side validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add a submit button
&lt;/h2&gt;

&lt;p&gt;We now have all the markup we need to collect the customers data for their hamburger order. However, they need a way to submit the order. Let’s go ahead and add a submit button that will send the data to the server when activated.&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Telephone: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custtel"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custemail"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Hamburger patty&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Beef &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Veggie &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Toppings&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Cheese &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Ketchup &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Mustard &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Pickle &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Onion &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Special instructions:
      &lt;span class="nt"&gt;&amp;lt;textarea&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"comments"&lt;/span&gt; &lt;span class="na"&gt;maxlength=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default action for a button is submit but it was added to the markup for clarity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding autocomplete functionality
&lt;/h2&gt;

&lt;p&gt;Some browsers try and help users fill out forms by autocompleting certain fields with previously stored information such as name and address. We can add the autocomplete attribute to certain inputs in an attempt to make it easier for the user to complete the form.&lt;/p&gt;

&lt;p&gt;Let’s add the autocomplete attribute to the following inputs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;customer name&lt;/li&gt;
&lt;li&gt;telephone number&lt;/li&gt;
&lt;li&gt;email address
&lt;/li&gt;
&lt;/ul&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;form&lt;/span&gt;
  &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://tasty.hamburgers.example.com/order"&lt;/span&gt;
  &lt;span class="na"&gt;enctype=&lt;/span&gt;&lt;span class="s"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
  &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Name: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custname"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;autocomplete=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Telephone: &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custtel"&lt;/span&gt; &lt;span class="na"&gt;autocomplete=&lt;/span&gt;&lt;span class="s"&gt;"tel"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &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;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address:
      &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"custemail"&lt;/span&gt; &lt;span class="na"&gt;autocomplete=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Hamburger patty&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Beef &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"patty"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Veggie &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Toppings&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Cheese &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Ketchup &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Mustard &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Pickle &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &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;
      &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"topping"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; Onion &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Special instructions:
      &lt;span class="nt"&gt;&amp;lt;textarea&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"comments"&lt;/span&gt; &lt;span class="na"&gt;maxlength=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;We covered the basic markup of an HTML form, form controls and introduced client-side validation and features like autocomplete. While this only scratches the surface of HTML forms, hopefully you now have a better understanding of the structure and functionality of them. In future posts I’ll continue with this example and style this form and build on the client-side validation by using JavaScript.&lt;/p&gt;

&lt;p&gt;You can find the source code for this form here:&lt;br&gt;
&lt;a href="https://gist.github.com/jordanholtdev/1dd0a0adacadfc5ec038a6451d7f0a96" rel="noopener noreferrer"&gt;Completed hamburger form&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Further resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://html.spec.whatwg.org/multipage/forms.html#forms" rel="noopener noreferrer"&gt;HTML Forms - WHATWG&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element#Forms" rel="noopener noreferrer"&gt;HTML Form Elements - MDN&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation" rel="noopener noreferrer"&gt;Client-side Validation - MDN&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input" rel="noopener noreferrer"&gt;The input element - MDN&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>codenewbie</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
