<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Mark&#39;s Dev Blog</title>
    <link>https://blog.isquaredsoftware.com/series/how-web-apps-work/index.xml</link>
    <description>Recent content on Mark&#39;s Dev Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <atom:link href="https://blog.isquaredsoftware.com/series/how-web-apps-work/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>How Web Apps Work: AJAX, APIs, and Data Transfer</title>
      <link>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-ajax-apis-data/</link>
      <pubDate>Sun, 22 Nov 2020 11:00:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-ajax-apis-data/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Web development is a huge field with a vast array of concepts, terms, tools, and technologies. For people just getting started in web dev, this landscape is often bewildering - it&#39;s unclear what most of these pieces are, much less how they fit together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This series provides an overview of fundamental web dev concepts and technologies, what these pieces are, why they&#39;re needed, and how they relate to each other&lt;/strong&gt;. It&#39;s not a completely exhaustive reference to everything in web development, nor is it a &amp;quot;how to build apps&amp;quot; guide. Instead, it&#39;s a map of the territory, &lt;strong&gt;intended to give you a sense of what the landscape looks like, and enough information that you can go research these terms and topics in more depth if needed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some of the descriptions will be more oriented towards modern client-side app development with JavaScript, but most of the topics in the series are fundamental enough that they apply to server-centric applications as well.&lt;/p&gt;

&lt;p&gt;Other posts in this series cover additional topics, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/&#34;&gt;HTTP and Servers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/&#34;&gt;Client Development and Deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/&#34;&gt;Browsers, HTML, and CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-javascript-dom/&#34;&gt;JavaScript and the DOM&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New terms will be marked in &lt;em&gt;italics&lt;/em&gt;. I&#39;ll link references for some of them, but encourage you to search for definitions yourself. Also, some of the descriptions will be simplified to avoid taking up too much space or dealing with edge cases. This post in particular does not attempt to be a &amp;quot;how to program&amp;quot; tutorial or complete reference to JS, but will point out common gotchas and differences from other languages like Java, C++, and Python.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript&#34;&gt;&lt;strong&gt;MDN JavaScript docs&lt;/strong&gt;&lt;/a&gt; have a complete set of resources on everything related to JavaScript, AJAX, and browser functionality&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;https://javascript.info/&#34;&gt;&lt;strong&gt;The Modern JavaScript Tutorial&lt;/strong&gt;&lt;/a&gt; has information on built-in AJAX APIs and browser storage.&lt;/p&gt;

&lt;p&gt;My &lt;a href=&#34;https://blog.isquaredsoftware.com/2019/05/presentation-js-for-java-devs/&#34;&gt;&lt;strong&gt;JavaScript for Java Developers slides&lt;/strong&gt;&lt;/a&gt; also cover much of this post&#39;s content as well, showing examples of JS syntax and concepts in a cheatsheet-type format. I&#39;ll link relevant sections of these slides throughout this post rather than copy entire large code blocks.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#json&#34;&gt;JSON&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#json-overview&#34;&gt;JSON Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#working-with-json&#34;&gt;Working with JSON&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#ajax&#34;&gt;AJAX&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#ajax-apis-and-libraries&#34;&gt;AJAX APIs and Libraries&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#xmlhttprequest&#34;&gt;&lt;code&gt;XMLHttpRequest&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#fetch&#34;&gt;&lt;code&gt;fetch&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#axios&#34;&gt;Axios&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#jquery&#34;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#other-request-libraries&#34;&gt;Other Request Libraries&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#http-request-variations&#34;&gt;HTTP Request Variations&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#polling&#34;&gt;Polling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#long-polling&#34;&gt;Long Polling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#http-streaming&#34;&gt;HTTP Streaming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#server-sent-events&#34;&gt;Server Sent Events&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#websockets&#34;&gt;Websockets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#cors&#34;&gt;CORS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#data-transfer-protocols&#34;&gt;Data Transfer Protocols&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#rest&#34;&gt;REST&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#rpc&#34;&gt;RPC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#graphql&#34;&gt;GraphQL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#browser-storage&#34;&gt;Browser Storage&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#cookies&#34;&gt;Cookies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#localstorage&#34;&gt;&lt;code&gt;localStorage&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#sessionstorage&#34;&gt;&lt;code&gt;sessionStorage&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#indexeddb&#34;&gt;&lt;code&gt;indexedDB&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#client-url-routing&#34;&gt;Client URL Routing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-resources&#34;&gt;Further Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;json&#34;&gt;JSON&lt;/h2&gt;

&lt;h3 id=&#34;json-overview&#34;&gt;JSON Overview&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;JSON&lt;/em&gt; is the most widely used data transfer format for web apps. JSON is short for &amp;quot;JavaScript Object Notation&amp;quot;, and is an adaptation of JS object/array syntax for use as a data format. All major programming languages have built-in support for reading and writing JSON data, but it naturally fits into JavaScript. JSON has become the de-facto standard data transfer format for HTTP-based APIs, and some databases even support storing and querying JSON document contents. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/77&#34;&gt;JSON&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;JSON syntax consists of normal JS objects and array definitions, including primitives like numbers, strings, booleans, and &lt;code&gt;null&lt;/code&gt;. However, JSON does have some additional rules and restrictions compared to normal JS syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No variables&lt;/li&gt;
&lt;li&gt;No comments&lt;/li&gt;
&lt;li&gt;All object keys must be quoted with double-quotes&lt;/li&gt;
&lt;li&gt;The final key in objects and the final item in arrays may not have a trailing comma&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The top level of JSON data may be either an object or an array (slides: (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/78&#34;&gt;JSON syntax examples&lt;/a&gt;))&lt;/p&gt;

&lt;p&gt;A typical JSON document for a list of todo objects might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-json&#34;&gt;[
  { &amp;quot;id&amp;quot;: 0, &amp;quot;text&amp;quot;: &amp;quot;Buy milk&amp;quot;, &amp;quot;completed&amp;quot;: false, &amp;quot;colors&amp;quot;: [&amp;quot;red&amp;quot;] },
  { &amp;quot;id&amp;quot;: 1, &amp;quot;text&amp;quot;: &amp;quot;Clean yard&amp;quot;, &amp;quot;completed&amp;quot;: true, &amp;quot;colors&amp;quot;: [] },
  {
    &amp;quot;id&amp;quot;: 2,
    &amp;quot;text&amp;quot;: &amp;quot;Read book&amp;quot;,
    &amp;quot;completed&amp;quot;: false,
    &amp;quot;colors&amp;quot;: [&amp;quot;red&amp;quot;, &amp;quot;blue&amp;quot;]
  }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Because JSON is a subset of JS syntax, it lacks several things that normal JS has. The inability to write comments is a frequently cited pain point. It also doesn&#39;t have native support for date values, so they have to be serialized as strings. You can write numbers in JSON of any size, but because JavaScript itself is limited to 64-bit floating point numbers, in practice that also limits the size of numbers you can pass via JSON.&lt;/p&gt;

&lt;h3 id=&#34;working-with-json&#34;&gt;Working with JSON&lt;/h3&gt;

&lt;p&gt;JSON content must be &lt;em&gt;serialized&lt;/em&gt; by converting it into a single string for transfer, and then &lt;em&gt;deserialized&lt;/em&gt; back into actual objects after it has been received.&lt;/p&gt;

&lt;p&gt;The JS language supports this with a pair of built-in functions: &lt;code&gt;JSON.stringify(value)&lt;/code&gt; will convert any valid value (object, array, primitive) into a complete string. &lt;code&gt;JSON.parse(string)&lt;/code&gt; will deserialize a string of JSON text back into its corresponding values.&lt;/p&gt;

&lt;p&gt;When sending JSON content over HTTP, the request or response should use the header &lt;code&gt;content-type: application/json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Most server frameworks have shortcuts built in for returning a JSON-formatted response. These methods often allow returning an object or array directly, and the framework takes care of serializing the data into JSON format and setting the right HTTP headers. For example, the Express server framework for Node has &lt;code&gt;res.json(obj)&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&#34;ajax&#34;&gt;AJAX&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;AJAX&lt;/em&gt; is a term used to describe making HTTP requests, via JavaScript, in the background of a page, without reloading it. It&#39;s an acronym that originally stood for &amp;quot;Asynchronous JavaScript And XML&amp;quot;. At the time the phrase was created, XML was the standard data transfer format used for most requests. Since then, JSON has completely replaced XML as the standard data transfer format. Today, the term &amp;quot;AJAX request&amp;quot; normally refers to fetching data in JSON format from a web server over HTTP.&lt;/p&gt;

&lt;p&gt;Browsers have a couple built-in APIs that are used for making AJAX requests: &lt;code&gt;XMLHttpRequest&lt;/code&gt; (XHR) and &lt;code&gt;fetch&lt;/code&gt;. XHR is generally considered to be a clunky, low-level, and hard to use API design. &lt;code&gt;fetch&lt;/code&gt; is intended to be a more modern replacement, but still has some noticeable annoyances in its design. Because of those, most apps use a third-party library that wraps one of those two built-in methods to provide an alternate API that is easier to use.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The term &amp;quot;API&amp;quot; always means &amp;quot;other code that you call to get something done&amp;quot;, but depending on context, it can mean &amp;quot;an actual function you call in your code&amp;quot;, or &amp;quot;a remote request to a server to fetch some data&amp;quot;. In the &amp;quot;AJAX&amp;quot; section, &amp;quot;API&amp;quot; refers to actual functions you call in your JS code. In the &lt;a href=&#34;#data-transfer-protocols&#34;&gt;Data Transfer Protocols&lt;/a&gt; section below, it refers to remote network requests to fetch data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Browsers can cache some HTTP response contents. This is most common with static files like HTML, CSS, and images, but other HTTP data responses can be cached as well. This is most likely to happen if the HTTP request is using the HTTP &lt;code&gt;GET&lt;/code&gt; method. Several HTTP headers also have an effect on caching as well.&lt;/p&gt;

&lt;h2 id=&#34;ajax-apis-and-libraries&#34;&gt;AJAX APIs and Libraries&lt;/h2&gt;

&lt;p&gt;AJAX API usage typically falls into three categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The built-in &lt;code&gt;XMLHttpRequest&lt;/code&gt; and &lt;code&gt;fetch&lt;/code&gt; APIs&lt;/li&gt;
&lt;li&gt;Third-party wrapper libraries like &lt;code&gt;axios&lt;/code&gt; and &lt;code&gt;jQuery&lt;/code&gt; that wrap the core APIs&lt;/li&gt;
&lt;li&gt;Higher-level data fetching abstractions that use the other APIs internally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many third-party AJAX wrapper libraries, so we&#39;ll briefly look at a couple of the most popular options here.&lt;/p&gt;

&lt;h3 id=&#34;xmlhttprequest&#34;&gt;&lt;code&gt;XMLHttpRequest&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;XMLHttpRequest&lt;/code&gt;, typically referred to as &amp;quot;XHR&amp;quot;, is the original browser API for making AJAX requests. It was introduced by Internet Explorer around 1999, and added by other browsers around over the next few years. Despite its name, it can be used to transfer any kind of content over HTTP, not just XML.&lt;/p&gt;

&lt;p&gt;XHR&#39;s API is based on creating an XHR object instance, and assigning callbacks to it for various request lifeycle events. That approach is notoriously hard to work with. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/82&#34;&gt;XHR examples&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;XHR is supported in all browsers, and in Node.js. Because it&#39;s available everywhere and has been around longer, it&#39;s often used as the core implementation of other AJAX libraries.&lt;/p&gt;

&lt;h3 id=&#34;fetch&#34;&gt;&lt;code&gt;fetch&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;fetch&lt;/code&gt; API is a newer built-in browser API, meant to be a replacement for XHR. It has a nicer syntax, and uses Promises for handling the responses. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/83&#34;&gt;&lt;code&gt;fetch&lt;/code&gt; examples&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;A typical &lt;code&gt;fetch&lt;/code&gt; request might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;fetch(&#39;http://example.com/api/users&#39;)
  .then((response) =&amp;gt; response.json())
  .then((users) =&amp;gt; {
    // do something with users data
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, &lt;code&gt;fetch&lt;/code&gt; has some behaviors that frequently surprise or annoy developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fetch&lt;/code&gt; only returns a rejected promise if the actual network request failed completely. As long as the server returns a response, &lt;code&gt;fetch&lt;/code&gt; will return a successfully resolved promise, even if the HTTP status code was a 4xx or 5xx HTTP error.&lt;/li&gt;
&lt;li&gt;The initial &lt;code&gt;fetch(&#39;/some/url&#39;)&lt;/code&gt; call returns a promise containing a &lt;code&gt;Response&lt;/code&gt; object. That object is &lt;em&gt;not&lt;/em&gt; the actual serialized data from the server. Instead, a second call is required to ask the response to return the request body content in a specific format, such as JSON.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fetch&lt;/code&gt; does not send cookies to the server by default - you must include a &lt;code&gt;credentials: &#39;same-origin&#39;&lt;/code&gt; option&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fetch&lt;/code&gt; does not automatically stringify objects or set headers when sending JSON - you must do those steps yourself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, &lt;code&gt;fetch&lt;/code&gt; is not supported in Internet Explorer or Node.js.&lt;/p&gt;

&lt;p&gt;Because of this, it&#39;s very common to use a library that wraps XHR or &lt;code&gt;fetch&lt;/code&gt;. For cases where you want to use &lt;code&gt;fetch&lt;/code&gt; but it&#39;s not available in your target environment, there are &lt;em&gt;polyfills&lt;/em&gt; to add a reimplementation of &lt;code&gt;fetch&lt;/code&gt; in environments that don&#39;t support it, such as &lt;a href=&#34;https://github.com/matthew-andrews/isomorphic-fetch&#34;&gt;&lt;code&gt;isomorphic-fetch&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;axios&#34;&gt;Axios&lt;/h3&gt;

&lt;p&gt;Axios is a widely popular AJAX wrapper library. Its API design is based on the &amp;quot;Resource&amp;quot; classes that were part of AngularJS 1.x, particularly the structure of its response objects.&lt;/p&gt;

&lt;p&gt;Axios makes common tasks fairly easy. The default &lt;code&gt;axios&lt;/code&gt; object has &lt;code&gt;.get()&lt;/code&gt; and &lt;code&gt;.post()&lt;/code&gt; methods, which return promises. The &lt;code&gt;.post()&lt;/code&gt; method accepts a data value as an argument, and if provided, automatically stringifies that into JSON and adds headers to the request. Axios response objects automatically deserialize JSON content, and the body content is always available in &lt;code&gt;response.data&lt;/code&gt;. A typical request might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;axios.get(&#39;http://www.example.com/api/users&#39;).then((response) =&amp;gt; {
  // do something with response.data
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Because it uses XHR internally, it works across all browsers as well as Node.&lt;/p&gt;

&lt;p&gt;Axios also provides some powerful capabilities like &lt;a href=&#34;https://github.com/axios/axios#interceptors&#34;&gt;&amp;quot;interceptors&amp;quot;&lt;/a&gt;, which allow modification of requests and responses. This is often used for adding auth headers or transforming data.&lt;/p&gt;

&lt;h3 id=&#34;jquery&#34;&gt;jQuery&lt;/h3&gt;

&lt;p&gt;jQuery was historically used to enable powerful DOM manipulations, while smoothing over DOM API differences between browsers. jQuery also includes an AJAX wrapper, &lt;code&gt;$.ajax()&lt;/code&gt;. Given the difficulties in working with the plain XHR API, jQuery&#39;s AJAX wrapper was another major reason for its popularity. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/85&#34;&gt;jQuery AJAX&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The jQuery AJAX API is nicer to work with than XHR, but definitely still shows that it was designed in an earlier era of JS usage. It primarily takes &lt;code&gt;success&lt;/code&gt; and &lt;code&gt;error&lt;/code&gt; callbacks, rather than working with promises. It does have the ability to handle responses by returning a precursor to Promises, called a &amp;quot;deferred&amp;quot;, and can automatically deserialize JSON data.&lt;/p&gt;

&lt;p&gt;If you&#39;re working on a simple site and already are using jQuery for other things, it&#39;s reasonable to use jQuery to make AJAX calls. Otherwise, prefer using a modern option like &lt;code&gt;fetch&lt;/code&gt; or &lt;code&gt;axios&lt;/code&gt;. Definitely do not add jQuery to a site &lt;em&gt;just&lt;/em&gt; to make AJAX calls.&lt;/p&gt;

&lt;h3 id=&#34;other-request-libraries&#34;&gt;Other Request Libraries&lt;/h3&gt;

&lt;p&gt;Many tools and frameworks come with their own HTTP request wrappers. For example, AngularJS 1.x had &lt;a href=&#34;https://docs.angularjs.org/api/ng/service/$http&#34;&gt;&lt;code&gt;$http&lt;/code&gt;&lt;/a&gt; for general requests and a higher-level &lt;a href=&#34;https://docs.angularjs.org/api/ngResource/service/$resource&#34;&gt;&lt;code&gt;$resource&lt;/code&gt;&lt;/a&gt; class for working with &lt;a href=&#34;#rest&#34;&gt;REST APIs&lt;/a&gt;, while modern Angular has an &lt;a href=&#34;https://angular.io/guide/http&#34;&gt;&lt;code&gt;HttpClient&lt;/code&gt; service&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since the &lt;code&gt;fetch&lt;/code&gt; API has several annoyances in its design, many users opt to &lt;a href=&#34;https://kentcdodds.com/blog/replace-axios-with-a-simple-custom-fetch-wrapper/&#34;&gt;write their own &lt;code&gt;fetch&lt;/code&gt; wrapper&lt;/a&gt; to customize the behavior, typically by auto-converting JSON data and rejecting promises on HTTP 4xx/5xx responses.&lt;/p&gt;

&lt;p&gt;Alternately, &lt;a href=&#34;https://github.com/developit/redaxios&#34;&gt;&lt;code&gt;redaxios&lt;/code&gt;&lt;/a&gt; is a reimplementation of much of the &lt;code&gt;axios&lt;/code&gt; API as a small wrapper around &lt;code&gt;fetch&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&#34;http-request-variations&#34;&gt;HTTP Request Variations&lt;/h2&gt;

&lt;p&gt;HTTP is inherently a request/response protocol. That means that a server can never initiate sending a message to a client by itself. However, there are many cases when it&#39;s necessary for a server to send data to a client based on an event that occurred in the server.&lt;/p&gt;

&lt;p&gt;Over the years, the community has come up with several workarounds. The modern solution to this problem is &lt;a href=&#34;#websockets&#34;&gt;Websockets&lt;/a&gt;, but it&#39;s useful to know about these other techniques as well.&lt;/p&gt;

&lt;h3 id=&#34;polling&#34;&gt;Polling&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Polling&lt;/em&gt; is the simplest option to implement. The client continually makes requests to the server every few seconds, on a timer. However, this is usually inefficient - most of the time the server won&#39;t have anything new to report, so the new request is a waste of time and bandwidth.&lt;/p&gt;

&lt;h3 id=&#34;long-polling&#34;&gt;Long Polling&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Long polling&lt;/em&gt; is a variation on the polling approach. Instead of continually making requests, the client opens one request to the server. If the server doesn&#39;t have any messages to report, it sleeps the request. The client still has the connection open, and continues to wait for a response from the server. Eventually, the server either has something new to report, or a timer expires. At that point, it wakes up the request, and finally sends back a response to the original open request connection.&lt;/p&gt;

&lt;p&gt;The client then immediately makes another request, and the server again either has something to send back immediately, or sleeps on the request.&lt;/p&gt;

&lt;p&gt;This approach requires a bit of coordination inside the server, but is more bandwidth-efficient.&lt;/p&gt;

&lt;h3 id=&#34;http-streaming&#34;&gt;HTTP Streaming&lt;/h3&gt;

&lt;p&gt;Once an HTTP connection is opened by the client, the server may continue to send data over the open connection without closing out the response, leaving it open indefinitely.&lt;/p&gt;

&lt;h3 id=&#34;server-sent-events&#34;&gt;Server Sent Events&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Server-Sent Events&lt;/em&gt; are a specific form of HTTP streaming that is actually part of the HTTP spec. The client creates an &lt;code&gt;EventSource&lt;/code&gt; object and adds an event listener callback, and the server writes specifically formatted content to the response over time.&lt;/p&gt;

&lt;h2 id=&#34;websockets&#34;&gt;Websockets&lt;/h2&gt;

&lt;p&gt;All of those HTTP-based approaches to 2-way message and data transfer have distinct limitations. &lt;em&gt;Websockets&lt;/em&gt; were created to address those limitations. Websockets allow opening a persistent connection between a client and a server, where either side may send messages over the connection at any time. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/89&#34;&gt;websockets&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;A websocket starts out as a standard HTTP request, but the client adds a header telling the server it wants to &amp;quot;upgrade&amp;quot; the connection to a websocket. A websocket is similar conceptually to an actual OS-level networking socket, and like all HTTP requests, the data is sent over an actual socket. But, it&#39;s a higher-level abstraction, and is much more limited API-wise compared to a low-level OS socket.&lt;/p&gt;

&lt;p&gt;Once created, either side can add event listeners to process received messages, and send messages over the connection. Messages can contain text or binary content.&lt;/p&gt;

&lt;p&gt;Today, websockets are the standard approach used to provide live updates to a page after it&#39;s been updated, such as updates to sports scores.&lt;/p&gt;

&lt;h2 id=&#34;cors&#34;&gt;CORS&lt;/h2&gt;

&lt;p&gt;HTTP requests often involve security and authorization concerns. As part of this, browsers specifically implement restrictions such as the &lt;em&gt;Same-Origin Policy&lt;/em&gt;, so that scripts can only interact with resources loaded from the exact same server URL. Additionally, a server may only want to allow interactions with its own scripts and client code that it has served, instead of requests from any arbitrary site or client.&lt;/p&gt;

&lt;p&gt;Browsers enforce this via &lt;em&gt;Cross Origin Resource Sharing (CORS)&lt;/em&gt;. By default, an AJAX request to any URL other than the original URL for a host page will cause the browser to make a &lt;em&gt;pre-flight request&lt;/em&gt; to ask the server &amp;quot;are you okay with other sites making data requests to you?&amp;quot;. The server may then respond with a set of URL patterns that are allowed to successfully make requests, or a value indicating &amp;quot;all requests are okay&amp;quot;. If the current client matches that pattern, the browser will actually make the real request.&lt;/p&gt;

&lt;p&gt;CORS is a frequent source of confusion for developers who are just trying to make a request and are surprised when the browser blocks it.&lt;/p&gt;

&lt;p&gt;Note that &lt;em&gt;only&lt;/em&gt; browsers implement CORS - HTTP requests made outside a browser, such as from another server or another non-browser environments do not enforce CORS. This can also be confusing - &amp;quot;it worked in my CLI tool / API test client, why doesn&#39;t it work in the browser?&amp;quot;.&lt;/p&gt;

&lt;h2 id=&#34;data-transfer-protocols&#34;&gt;Data Transfer Protocols&lt;/h2&gt;

&lt;p&gt;HTTP provides the standard mechanism for making &lt;em&gt;some&lt;/em&gt; kind of request and response to a server. However, there are many ways that a server may structure its URLs and the expected format of requests and responses. In order to write code that makes requests to a server, you must know what structure and request formats that server expects your client to use.&lt;/p&gt;

&lt;p&gt;There are numerous variations on how server data APIs are structured, but there are a few common categories of API structures you&#39;ll see frequently. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/81&#34;&gt;AJAX API design approaches&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;With all these approaches, the server defines specific &lt;em&gt;endpoints&lt;/em&gt; - combinations of URLs, HTTP methods, and expected request/response formats.&lt;/p&gt;

&lt;h3 id=&#34;rest&#34;&gt;REST&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;REST&lt;/em&gt; stands for &amp;quot;Representational State Transfer&amp;quot;. A REST API is an HTTP-based API that uses URLs and HTTP methods as the primary approach for determining what kind of request the client is making, and how the server should handle that request.&lt;/p&gt;

&lt;p&gt;REST APIs are often used for &lt;em&gt;CRUD (Create/Retrieve/Update/Delete)&lt;/em&gt; apps, where the app is conceptually doing operations to update data in a database on the server (&amp;quot;create this thing&amp;quot;, &amp;quot;give me a list of these things&amp;quot;, &amp;quot;update that thing&amp;quot;, &amp;quot;delete that thing&amp;quot;).&lt;/p&gt;

&lt;p&gt;There are frequent arguments over what exactly constitutes a true REST API, but in general, a REST API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Offers different URLs for each kind of &amp;quot;resource&amp;quot; that it supports&lt;/li&gt;
&lt;li&gt;Expects different HTTP methods to be used for different kinds of operations on the same resource URL. Typically, HTTP &lt;code&gt;POST/GET/PUT/DELETE&lt;/code&gt; map to relevant CRUD operations.&lt;/li&gt;
&lt;li&gt;Returns different HTTP status codes to indicate success or failure of the request&lt;/li&gt;
&lt;li&gt;Expects key pieces of data like item IDs to be included as part of the actual URL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example REST API usage might look like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get list of users: &lt;code&gt;GET /users&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Get one user: &lt;code&gt;GET /users/42&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Create one user: &lt;code&gt;POST /users/42&lt;/code&gt; (body: &lt;code&gt;{name : &amp;quot;Mark&amp;quot;}&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Update user: &lt;code&gt;PUT /users/42&lt;/code&gt; (body: &lt;code&gt;{name : &amp;quot;Mark&amp;quot;}&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many server web frameworks have built-in support for defining a set of REST API endpoints based on metadata.&lt;/p&gt;

&lt;h3 id=&#34;rpc&#34;&gt;RPC&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;RPC&lt;/em&gt; stands for &amp;quot;Remote Procedure Call&amp;quot;. This is a general style of network request that is intended to mimic a normal function call in your code, but with the actual logic running on some other server. There have been many RPC tools over the years for many languages. Here, the focus is on RPC-style HTTP requests.&lt;/p&gt;

&lt;p&gt;An RPC-style approach describes &amp;quot;methods&amp;quot; to be &amp;quot;called&amp;quot;, instead of &amp;quot;resources&amp;quot; to be &amp;quot;operated on&amp;quot;. Unlike a REST API, an RPC-style API will likely define URLs whose paths look like verbs or function names instead of nouns.&lt;/p&gt;

&lt;p&gt;For example, an HTTP-based RPC server approach might look like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get a list of users: &lt;code&gt;GET /getUsers&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Get one user: &lt;code&gt;POST /getUser&lt;/code&gt; (body: &lt;code&gt;{userId : 42}&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Create one user: &lt;code&gt;POST /createUser&lt;/code&gt; (body: &lt;code&gt;{userId : 42, name : &amp;quot;Mark&amp;quot;}&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Update one user: &lt;code&gt;POST /updateUser&lt;/code&gt; (body: &lt;code&gt;{userId : 42, name : &amp;quot;Mark&amp;quot;}&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alternately, there might be a single URL endpoint, and the request could have the name of the &amp;quot;method to call&amp;quot; in the body. The JSON-RPC spec uses this approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;POST /jsonrpc&lt;/code&gt; (body: &lt;code&gt;{&amp;quot;method&amp;quot;: &amp;quot;createUser&amp;quot;, userId : 42, name : &amp;quot;Mark&amp;quot;}&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Either way, the response is likely to have an HTTP 200 status code indicating that the server returned a response successfully, but the contents of the response might have some kind of a field indicating whether the actual operation succeeded, like &lt;code&gt;{status: &#39;failed&#39;}&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&#34;graphql&#34;&gt;GraphQL&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;GraphQL&lt;/em&gt; is a relatively recent data transfer protocol created by Facebook. Conceptually, GraphQL is a defined format for API request and response content. In addition, there is an ecosystem of client and server tools that are typically used that abstract the details of making a GraphQL-formatted query, processing the request on the server and fetching requested data, formatting the response correctly, and caching the data on the client. Most discussions of &amp;quot;using GraphQL&amp;quot; assume use of the most popular libraries and tools for working with GraphQL.&lt;/p&gt;

&lt;p&gt;With GraphQL, the server offers a single URL endpoint, and defines &lt;em&gt;schemas&lt;/em&gt; that describe what data types it supports and how they relate to each other. The client sends a GraphQL &lt;em&gt;query&lt;/em&gt; request that asks for some subset of those data types, and defines the expected structure of the response format. The server then &lt;em&gt;resolves&lt;/em&gt; the requested data types, extracts the requested fields for each type, formats the response as requested by the client, and sends the data back. The server may also support &lt;em&gt;mutations&lt;/em&gt;, which allow the client to create/update/delete data, and &lt;em&gt;subscriptions&lt;/em&gt; for changes to query results over time.&lt;/p&gt;

&lt;p&gt;GraphQL requests are almost always HTTP POSTs, and subscriptions are typically built on top of websockets.&lt;/p&gt;

&lt;p&gt;GraphQL query syntax looks somewhat like JSON, but without commas or values:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;{
  hero {
    name
    friends {
      name
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which might result in this JSON response from the server:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;{
  &amp;quot;data&amp;quot;: {
    &amp;quot;hero&amp;quot;: {
      &amp;quot;name&amp;quot;: &amp;quot;R2-D2&amp;quot;,
      &amp;quot;friends&amp;quot;: [
        {&amp;quot;name&amp;quot;: &amp;quot;Luke Skywalker&amp;quot;},
        {&amp;quot;name&amp;quot;: &amp;quot;Han Solo&amp;quot;},
        {&amp;quot;name&amp;quot;: &amp;quot;Leia Organa&amp;quot;}
      ]
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;GraphQL moves a lot of the query complexity to the server, and gives clients a lot of flexibility in what data they want to ask for. This can simplify cases where different portions of an app need to fetch different subsets of the same data and reduce the need to make numerous calls to fetch related values. On the other hand, it can be more difficult to deal with things like auth and business logic as part of the data resolution on the server, and the most popular GraphQL clients are very heavyweight.&lt;/p&gt;

&lt;h2 id=&#34;browser-storage&#34;&gt;Browser Storage&lt;/h2&gt;

&lt;p&gt;In addition to all these network requests for data fetching, browsers also offer several tools for storing data within the browser itself. These are typically used to manage data related to user sessions and preferences, but can be used for other scenarios as well.&lt;/p&gt;

&lt;h3 id=&#34;cookies&#34;&gt;Cookies&lt;/h3&gt;

&lt;p&gt;Browsers allow servers to set &lt;em&gt;cookies&lt;/em&gt; - small pieces of text associated with a given URL. Any cookies set by a site will then be included on future requests to that site. Cookies are typically limited to a couple KB in length, and are most often used to store a unique session ID that can be read by the server to retrieve additional session data from a database or in memory. Cookies can have expiration timestamps set by the server.&lt;/p&gt;

&lt;p&gt;Cookies can be a source of security issues. A server can add an &lt;code&gt;HttpOnly&lt;/code&gt; attribute when setting a cookie to ensure that JS code cannot read or modify that cookie.&lt;/p&gt;

&lt;h3 id=&#34;localstorage&#34;&gt;&lt;code&gt;localStorage&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;localStorage&lt;/code&gt; is a browser API that lets client code save key/value string data, then retrieve it later. &lt;code&gt;localStorage&lt;/code&gt; persists indefinitely, so it&#39;s often used to save user settings so they can be reloaded the next time the user visits a page. An example of this might look like &lt;code&gt;localStorage.setItem(&#39;userPrefs&#39;, JSON.stringify(userData))&lt;/code&gt;, and then reversing the process when a page is loaded. Data in &lt;code&gt;localStorage&lt;/code&gt; can only be read by code from the same origin, and is limited to about 2MB in size.&lt;/p&gt;

&lt;h3 id=&#34;sessionstorage&#34;&gt;&lt;code&gt;sessionStorage&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;sessionStorage&lt;/code&gt; has the same basic API methods as &lt;code&gt;localStorage&lt;/code&gt;, but is isolated on a per-tab basis. It will persist between tab reloads, but is cleared when the user closes the tab.&lt;/p&gt;

&lt;h3 id=&#34;indexeddb&#34;&gt;&lt;code&gt;indexedDB&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;A more powerful database-style storage system that can hold larger amounts of data.&lt;/p&gt;

&lt;h2 id=&#34;client-url-routing&#34;&gt;Client URL Routing&lt;/h2&gt;

&lt;p&gt;In &lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/&#34;&gt;HTTP and Servers&lt;/a&gt;, we talked about the idea of &lt;em&gt;routing&lt;/em&gt;: determing application behavior based on the URL. For application servers, routing means looking at a URL and HTTP method, and choosing the right application handler logic to process that request.&lt;/p&gt;

&lt;p&gt;Client-side applications can do their own form of routing. Browsers offer access to the current URL via &lt;code&gt;window.location&lt;/code&gt;, and the browser&#39;s URL history via a &lt;code&gt;history&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Client applications can parse the URL and use that as the basis for dynamically showing and hiding portions of the UI, without needing to make an additional request to the server. Client-side routers typically offer special forms of a link tag that handle clicks by calling &lt;code&gt;history.push(&#39;/new-route&#39;)&lt;/code&gt; to alter the URL, and then read the updated route to switch to showing a different piece of UI.&lt;/p&gt;

&lt;p&gt;However, client routing does add additional complications. If the browser tries to reload a client-routed URL by itself, the server now has to handle that URL somehow with a valid response. Typically, the server is configured so that if a URL like &lt;code&gt;/some-route&lt;/code&gt; is not recognized, it returns the entire index page with the full JS bundle as the response, just as if the browser requested the &lt;code&gt;/&lt;/code&gt; URL. Once the content is loaded, the client router kicks in, sees that &lt;code&gt;/some-route&lt;/code&gt; is the active URL, and immediately shows the relevant content on the client side.&lt;/p&gt;

&lt;h2 id=&#34;further-resources&#34;&gt;Further Resources&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JSON&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON&#34;&gt;MDN: Working with JSON&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.infoworld.com/article/3222851/what-is-json-a-better-format-for-data-exchange.html&#34;&gt;What is JSON?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AJAX&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Ajax_(programming)&#34;&gt;Wikipedia: AJAX&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX&#34;&gt;MDN: AJAX guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://javascript.info/network&#34;&gt;The Modern JS Tutorial: Network Requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developers.google.com/web/ilt/pwa/working-with-the-fetch-api&#34;&gt;Working with the &lt;code&gt;fetch&lt;/code&gt; API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.taniarascia.com/how-to-connect-to-an-api-with-javascript/&#34;&gt;How to connect to an API with JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HTTP Request Variations&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.ably.io/topic/long-polling&#34;&gt;Long Polling - Concepts and Considerations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.turtle-techies.com/long-polling-vs-server-sent-events/&#34;&gt;Long Polling vs Server Sent Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://datto.engineering/post/powering-a-live-ui-with-server-sent-events&#34;&gt;Using Server Sent Events to Power a Live UI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Websockets&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/WebSocket&#34;&gt;Wikipedia: Websockets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.ably.io/topic/websockets&#34;&gt;Websockets: A Conceptual Deep Dive&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.ably.io/blog/websockets-vs-long-polling/&#34;&gt;Websockets vs Long Polling&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@baphemot/understanding-cors-18ad6b478e2b&#34;&gt;Understanding CORS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://auth0.com/blog/cors-tutorial-a-guide-to-cross-origin-resource-sharing/&#34;&gt;CORS Tutorial: A Guide to Cross-Origin Resource Sharing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data Transfer Protocols&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/&#34;&gt;Understanding RPC vs REST for HTTP APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://apisyouwonthate.com/blog/understanding-rpc-rest-and-graphql&#34;&gt;Understanding RPC, REST, and GraphQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://apihandyman.io/do-you-really-know-why-you-prefer-rest-over-rpc/&#34;&gt;Comparing REST and RPC APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://stackoverflow.com/questions/26830431/web-service-differences-between-rest-and-rpc&#34;&gt;Stack Overflow: What is the difference between REST and RPC web services?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://filipaivars.pt/2019/03/18/api-paradigms-and-when-to-use-them/&#34;&gt;API Paradigms - which and when to use them&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://iximiuz.com/en/posts/api-developers-never-rest/&#34;&gt;API Developers Never REST&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.restapitutorial.com/&#34;&gt;REST API Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://graphql.org/&#34;&gt;GraphQL.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.jsonrpc.org/&#34;&gt;JSON-RPC.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Browser Storage&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://css-tricks.com/a-primer-on-the-different-types-of-browser-storage/&#34;&gt;A Primer on the Different Types of Browser Storage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies&#34;&gt;MDN: Cookies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://javascript.info/data-storage&#34;&gt;The Modern JS Tutorial: Storing data in the browser&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Client Routing&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/History_API&#34;&gt;MDN: History API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://krasimirtsonev.com/blog/article/deep-dive-into-client-side-routing-navigo-pushstate-hash&#34;&gt;Deep dive into client-side routing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://willtaylor.blog/client-side-routing-in-vanilla-js/&#34;&gt;Understanding client side routing by implementing a router in vanilla JS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>How Web Apps Work: JavaScript and the DOM</title>
      <link>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-javascript-dom/</link>
      <pubDate>Sun, 15 Nov 2020 16:00:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-javascript-dom/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Web development is a huge field with a vast array of concepts, terms, tools, and technologies. For people just getting started in web dev, this landscape is often bewildering - it&#39;s unclear what most of these pieces are, much less how they fit together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This series provides an overview of fundamental web dev concepts and technologies, what these pieces are, why they&#39;re needed, and how they relate to each other&lt;/strong&gt;. It&#39;s not a completely exhaustive reference to everything in web development, nor is it a &amp;quot;how to build apps&amp;quot; guide. Instead, it&#39;s a map of the territory, &lt;strong&gt;intended to give you a sense of what the landscape looks like, and enough information that you can go research these terms and topics in more depth if needed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some of the descriptions will be more oriented towards modern client-side app development with JavaScript, but most of the topics in the series are fundamental enough that they apply to server-centric applications as well.&lt;/p&gt;

&lt;p&gt;Other posts in this series cover additional topics, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/&#34;&gt;HTTP and Servers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/&#34;&gt;Client Development and Deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/&#34;&gt;Browsers, HTML, and CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-ajax-apis-data/&#34;&gt;AJAX, APIs, and Data Transfer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New terms will be marked in &lt;em&gt;italics&lt;/em&gt;. I&#39;ll link references for some of them, but encourage you to search for definitions yourself. Also, some of the descriptions will be simplified to avoid taking up too much space or dealing with edge cases. This post in particular does not attempt to be a &amp;quot;how to program&amp;quot; tutorial or complete reference to JS, but will point out common gotchas and differences from other languages like Java, C++, and Python.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript&#34;&gt;&lt;strong&gt;MDN JavaScript docs&lt;/strong&gt;&lt;/a&gt; have a complete set of resources on JavaScript ranging from intro-level tutorials to detailed API references.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;https://www.freecodecamp.org/&#34;&gt;&lt;strong&gt;FreeCodeCamp&lt;/strong&gt;&lt;/a&gt; has multiple courses that cover JavaScript usage as well as other aspects of web dev.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;https://javascript.info/&#34;&gt;&lt;strong&gt;The Modern JavaScript Tutorial&lt;/strong&gt;&lt;/a&gt; is an excellent and thorough set of explanations of JS syntax and DOM APIs.&lt;/p&gt;

&lt;p&gt;My &lt;a href=&#34;https://blog.isquaredsoftware.com/2019/05/presentation-js-for-java-devs/&#34;&gt;&lt;strong&gt;JavaScript for Java Developers slides&lt;/strong&gt;&lt;/a&gt; also cover much of this post&#39;s content as well, showing examples of JS syntax and concepts in a cheatsheet-type format. I&#39;ll link relevant sections of these slides throughout this post rather than copy entire large code blocks.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#javascript-overview&#34;&gt;JavaScript Overview&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#language-evolution&#34;&gt;Language Evolution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#runtime-environments&#34;&gt;Runtime Environments&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#js-development-constraints&#34;&gt;JS Development Constraints&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#core-language&#34;&gt;Core Language&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#basic-syntax&#34;&gt;Basic Syntax&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#data-types&#34;&gt;Data Types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#conditional-logic&#34;&gt;Conditional Logic&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#comparisons-and-boolean-conversions&#34;&gt;Comparisons and Boolean Conversions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#functions&#34;&gt;Functions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#js-in-depth&#34;&gt;JS in Depth&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#objects&#34;&gt;Objects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#arrays&#34;&gt;Arrays&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#scoping-and-closures&#34;&gt;Scoping and Closures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#functions-and-this&#34;&gt;Functions and &lt;code&gt;this&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#classes-and-prototypes&#34;&gt;Classes and Prototypes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#async&#34;&gt;Async&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#timers-and-the-event-loop&#34;&gt;Timers and the Event Loop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#promises&#34;&gt;Promises&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#async-await-syntax-for-promises&#34;&gt;&lt;code&gt;async/await&lt;/code&gt; Syntax for Promises&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#other-topics&#34;&gt;Other Topics&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#js-module-formats&#34;&gt;JS Module Formats&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#regular-expressions&#34;&gt;Regular Expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#immutability&#34;&gt;Immutability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#lodash&#34;&gt;Lodash&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#dom&#34;&gt;DOM&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#dom-query-apis&#34;&gt;DOM Query APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#dom-manipulation&#34;&gt;DOM Manipulation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#event-listeners&#34;&gt;Event Listeners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#jquery&#34;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-resources&#34;&gt;Further Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;javascript-overview&#34;&gt;JavaScript Overview&lt;/h2&gt;

&lt;p&gt;JavaScript is a dynamic interpreted language that is primarily used in web browsers, but can also be used outside a browser environment. It was created in the mid-1990s by Brendan Eich at Netscape, and takes inspiration from the Java, Scheme, and Self languages. Since then, it has grown from a tiny scripting language to the world&#39;s most popular language. It&#39;s definitely not a &amp;quot;toy&amp;quot; - it can be used to write anything from small scripts to HTTP server applications to complex client-side web apps with hundreds of thousands of lines of code.&lt;/p&gt;

&lt;p&gt;JS is multi-paradigm - it can be used for Object-Oriented Programming similar to Java or C#, but can also be used in a Functional Programming style as well.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Despite its name, &lt;strong&gt;JavaScript has &lt;em&gt;no&lt;/em&gt; actual relation to the Java language!&lt;/strong&gt; Some aspects of JS&#39;s syntax were indeed borrowed from Java, but they are completely different languages. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/18&#34;&gt;Java vs JavaScript comparison table&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;language-evolution&#34;&gt;Language Evolution&lt;/h3&gt;

&lt;p&gt;To understand modern JS, it helps to understand how the language has evolved over time. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/10&#34;&gt;JS language timeline&lt;/a&gt;) There&#39;s &lt;a href=&#34;https://www.jetbrains.com/lp/javascript-25/&#34;&gt;a neat timeline of milestones in JS history&lt;/a&gt; that helps visualize some of the key events and changes over time.&lt;/p&gt;

&lt;p&gt;JS was standardized early on by the ECMA standards organization. Since &amp;quot;JavaScript&amp;quot; was trademarked, the standardized name is &amp;quot;ECMAScript&amp;quot;, and the specification is often referred to as the &amp;quot;ES Spec&amp;quot;. Early revisions were numbered: &amp;quot;ES2&amp;quot;, &amp;quot;ES3&amp;quot;, etc. The ES spec is maintained by a committee known as &lt;em&gt;TC39&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The ES spec has had several new revisions published over time, which added new language syntax and features. However, the ES4 spec revision grew so large that it was abandoned in 2003 due to disagreements over potential features.&lt;/p&gt;

&lt;p&gt;As a result, when the ES5 spec came out in 2009, it only added some relatively minor changes to the language.&lt;/p&gt;

&lt;p&gt;The next major spec revision, ES6, didn&#39;t come out until 2015. Because of the long wait between revisions and the rapid growth in JS popularity and usage, the ES6 spec was huge and doubled the amount of syntax and features in the language.&lt;/p&gt;

&lt;p&gt;You can roughly divide JS history and syntax into &amp;quot;before ES6&amp;quot; and &amp;quot;after ES6&amp;quot;. All the old syntax still works, but ES6 drastically changed how JS developers write code.&lt;/p&gt;

&lt;p&gt;After the ES6 spec was finished, the TC39 committee changed how they design changes to the JS language. Now, individual features are proposed and go through a series of stages over time (proposal, early implementation, completed implementation, finalized). New spec revisions are published yearly, and any new features finalized since the last revision are added to the new spec. Revisions are now known by year: ES2016, ES2017, and so on. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/12&#34;&gt;TC39 stages and process&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To give a sense of how these revisions have changed the language over time, here&#39;s an incomplete list of new features by revision:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ES3 (1999): regular expressions; &lt;code&gt;try/catch&lt;/code&gt; blocks and exceptions&lt;/li&gt;
&lt;li&gt;ES5 (2009): object and array methods; JSON parsing; function binding; syntax cleanup&lt;/li&gt;
&lt;li&gt;ES6 (2015): &lt;code&gt;let/const&lt;/code&gt; variable declarations; arrow functions; classes; object literal shorthand; template strings; promises; generators; default function arguments; array spread syntax; module syntax; proxies&lt;/li&gt;
&lt;li&gt;ES2016: &lt;code&gt;Array.includes()&lt;/code&gt;, &lt;code&gt;**&lt;/code&gt; exponent operator&lt;/li&gt;
&lt;li&gt;ES2017: &lt;code&gt;async/await&lt;/code&gt; functions; &lt;code&gt;Object.values() / Object.entries()&lt;/code&gt;; trailing commas in function args&lt;/li&gt;
&lt;li&gt;ES2018: async iteration; object rest/spread operators; &lt;code&gt;Promise.finally()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see, ES6 was huge, while ES2016 was tiny. Since then, the rate of new features has been slower, but steady. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/13&#34;&gt;ES spec revisions and features&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&#34;runtime-environments&#34;&gt;Runtime Environments&lt;/h3&gt;

&lt;p&gt;JavaScript was originally invented to give web browsers the ability to have interactive logic running inside a web page. By the mid 2000s, all browsers included a JS interpreter, and developers were starting to write larger client-side applications in JS.&lt;/p&gt;

&lt;p&gt;In 2009, Ryan Dahl announced &lt;em&gt;Node.js&lt;/em&gt; - a JS runtime for executing JS outside of a browser environment. Node is built on top of Chrome&#39;s V8 JS engine, and adds a standard library of APIs for things like working with the local filesystem, network sockets, and more. Node also popularized the CommonJS module format and the NPM package management tool.&lt;/p&gt;

&lt;p&gt;Today, JS is widely used in multiple environments for many kinds of projects. The primary use cases are interactivity in web pages, full web app clients, web app servers, and build tools.&lt;/p&gt;

&lt;p&gt;So, some JS code is meant to run exclusively in a browser, some is meant to run exclusively under Node, and some code can work in both environments.&lt;/p&gt;

&lt;h3 id=&#34;js-development-constraints&#34;&gt;JS Development Constraints&lt;/h3&gt;

&lt;p&gt;The other key factor to understand in how JS has evolved and how it&#39;s used is the set of unique constraints web developers face. There&#39;s a great quote from one of the early browser developers that encapsulates this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The by-design purpose of JavaScript was to make the monkey dance when you moused over it&lt;/strong&gt;. Scripts were often a single line. We considered ten line scripts to be pretty normal, hundred line scripts to be huge, and thousand line scripts were unheard of. The language was absolutely not designed for programming in the large, and our implementation decisions, performance targets, and so on, were based on that assumption.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eric Lippert, former IE/JS developer at Microsoft&lt;br /&gt;
&lt;a href=&#34;http://programmers.stackexchange.com/a/221658/214387&#34;&gt;http://programmers.stackexchange.com/a/221658/214387&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Compared to many other languages, JS is very different:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No built-in module definition system (until ES6)&lt;/li&gt;
&lt;li&gt;No built-in private / public encapsulation&lt;/li&gt;
&lt;li&gt;Prototypal-based inheritance system unlike most languages&lt;/li&gt;
&lt;li&gt;No static type declarations or compilation&lt;/li&gt;
&lt;li&gt;Dynamically modified objects and data&lt;/li&gt;
&lt;li&gt;Minimal standard library&lt;/li&gt;
&lt;li&gt;Variations in browser capabilities&lt;/li&gt;
&lt;li&gt;Entire codebase has to be shipped to the browser every time a page is loaded, then parsed and executed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of this, web client developers need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimize bytes sent over the wire&lt;/li&gt;
&lt;li&gt;Handle browser compatibility issues&lt;/li&gt;
&lt;li&gt;Fill in gaps in the JS standard library and language spec&lt;/li&gt;
&lt;li&gt;Reuse and share code between apps&lt;/li&gt;
&lt;li&gt;Build increasingly complex full-blown applications that just happen to live inside a browser&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;core-language&#34;&gt;Core Language&lt;/h2&gt;

&lt;h3 id=&#34;basic-syntax&#34;&gt;Basic Syntax&lt;/h3&gt;

&lt;p&gt;JS uses much of the typical syntax seen in the C family of languages (C, C++, Java, and C#). Statements end with semicolons, variable names are case-sensitive, blocks are denoted with curly braces, comments can be written with &lt;code&gt;//&lt;/code&gt; for a single line and &lt;code&gt;/* */&lt;/code&gt; for multiple lines, conditional logic uses &lt;code&gt;if/else&lt;/code&gt;, and there are variations of &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; for looping.&lt;/p&gt;

&lt;p&gt;Semicolons are actually optional - the interpreter will automatically insert them in places where they&#39;re strictly needed. That said, there&#39;s an ongoing argument between people who prefer using semis and those who avoid them. (Personally, I&#39;m in favor of always using semicolons.)&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;console.log()&lt;/code&gt; statement is the standard method for printing to the screen or the browser&#39;s debugging console. It accepts multiple arguments, including strings, objects, arrays, and other values, and will attempt to pretty-format any complex value. Other console methods exist, such as &lt;code&gt;console.error()&lt;/code&gt; for error-formatted messages, as well as specialty formatting methods like &lt;code&gt;console.table()&lt;/code&gt; and &lt;code&gt;console.group()&lt;/code&gt;. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/24&#34;&gt;comments and logging&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; keywords are used to declare variables, and are &lt;em&gt;block-scoped&lt;/em&gt; - they scope the lifetime of variable to the nearest curly brace block. &lt;code&gt;let&lt;/code&gt; variables can be assigned a new value, while &lt;code&gt;const&lt;/code&gt; variables cannot be changed to point to something else. There&#39;s also an older &lt;code&gt;var&lt;/code&gt; keyword, which has more confusing scoping behavior - it&#39;s &lt;em&gt;function-scoped&lt;/em&gt;, which means that no matter where you use &lt;code&gt;var&lt;/code&gt; to declare a variable, it&#39;s &lt;em&gt;hoisted&lt;/em&gt; and acts as if it was declared at the first line of the function it&#39;s in. Modern JS usage avoids &lt;code&gt;var&lt;/code&gt;, since &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; behave more consistently. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/26&#34;&gt;basic variable declarations&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;As a personal recommendation, I suggest using &lt;code&gt;const&lt;/code&gt; as the default, and &lt;code&gt;let&lt;/code&gt; if you plan to reassign to that variable later, but there&#39;s others who suggest just using &lt;code&gt;let&lt;/code&gt; all the time.&lt;/p&gt;

&lt;p&gt;JS only has a single number type: a 64-bit floating point number equivalent to a &lt;code&gt;double&lt;/code&gt; in other languages. It can hold integer values as well. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/28&#34;&gt;numbers and math methods&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Strings can be written using three different quotes: single quotes and double quotes are equivalent, while the newer &lt;em&gt;template literal strings&lt;/em&gt; use backticks and can have variable values interpolated in the middle. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/29&#34;&gt;string syntax and methods&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Booleans are written as &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;. Objects and arrays are normally written using &lt;em&gt;object/array literal&lt;/em&gt; syntax, as &lt;code&gt;{}&lt;/code&gt; for objects and &lt;code&gt;[]&lt;/code&gt; for arrays. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/31&#34;&gt;basic object syntax&lt;/a&gt;, &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/32&#34;&gt;basic array syntax&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Object keys are always strings, but if the key name is a valid JS variable name, the quotes can be omitted (and usually are).&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const text1 = &#39;Test A&#39;;
let text2 = &#39;Test B&#39;;
const value = 42;
// This is a template literal string
const text3 = `The number is ${value}`;
/* 
  This log statement can take multiple arguments
*/
console.log(&#39;First variable: &#39;, text1, &#39;second variable: &#39;, text2);

const object1 = {
  field1: 123,
  field2: true,
};

const array1 = [text1, value, object1, 99];
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;data-types&#34;&gt;Data Types&lt;/h3&gt;

&lt;p&gt;JS has a variety of core data types. The basic data types are standalone values called &lt;em&gt;primitives&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;undefined&lt;/code&gt; : a variable that has not been assigned a value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;null&lt;/code&gt;: a value that represents &amp;quot;no value&amp;quot;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;String&lt;/code&gt;: text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Number&lt;/code&gt; : a 64-bit floating point number (aka IEEE double)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Boolean&lt;/code&gt; : a true / false value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Symbol&lt;/code&gt;: a unique reference value that can be used as a form of singleton identifier&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All other values in JS are &lt;em&gt;objects&lt;/em&gt;. This includes actual plain objects, as well as other types that extend from the &lt;code&gt;Object&lt;/code&gt; type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Object&lt;/code&gt;: a collection of string key / any value properties

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Function&lt;/code&gt; : a function that can be called&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Array&lt;/code&gt; : an expandable list of values&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Date&lt;/code&gt; : a date/time value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RegExp&lt;/code&gt; : a regular expression&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The difference between &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; is subtle. &lt;code&gt;undefined&lt;/code&gt; represents &amp;quot;there is no meaningful value here&amp;quot;, while &lt;code&gt;null&lt;/code&gt; means &amp;quot;there is a value, but it&#39;s empty / not available&amp;quot;.&lt;/p&gt;

&lt;p&gt;Most of the other core data types have both a constructor function form and a literal syntax form, like &lt;code&gt;new String(&#39;abcd&#39;)&lt;/code&gt; vs &lt;code&gt;&#39;abcd&#39;&lt;/code&gt;, or &lt;code&gt;new Array()&lt;/code&gt; vs &lt;code&gt;[]&lt;/code&gt;. Always prefer using the literal syntax to create new values instead of creating them via constructors.&lt;/p&gt;

&lt;p&gt;Functions, arrays, dates, and regexps are technically objects as well.&lt;/p&gt;

&lt;h3 id=&#34;conditional-logic&#34;&gt;Conditional Logic&lt;/h3&gt;

&lt;p&gt;JS uses the standard C-like &lt;code&gt;if/else if/else&lt;/code&gt; syntax for conditions, as well as the ternary operator (&lt;code&gt;const value = condition ? trueValue : falseValue&lt;/code&gt;). There&#39;s also a typical &lt;code&gt;switch/case/break&lt;/code&gt; statement. Comparisons include the usual &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt; operators and &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, and &lt;code&gt;!&lt;/code&gt; boolean logic operators. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/34&#34;&gt;conditional statements&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There are several forms of loops. You can do C-style counting loops with &lt;code&gt;for(let i = 0; i &amp;lt; someValue; i++)&lt;/code&gt;. The &lt;code&gt;for (let key in obj)&lt;/code&gt; form iterates over keys, while &lt;code&gt;for (let item of items)&lt;/code&gt; form will loop over values inside an &lt;em&gt;iterable&lt;/em&gt; like an array. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/35&#34;&gt;loops&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;try/catch/finally&lt;/code&gt; allows handling errors. There&#39;s an &lt;code&gt;Error&lt;/code&gt; class, but technically any value can be thrown.&lt;/p&gt;

&lt;h3 id=&#34;comparisons-and-boolean-conversions&#34;&gt;Comparisons and Boolean Conversions&lt;/h3&gt;

&lt;p&gt;Unlike strictly-typed languages, JS frequently does &lt;em&gt;implicit conversions&lt;/em&gt; or &lt;em&gt;coercions&lt;/em&gt; of values in various contexts. The most common example is treating values as &lt;em&gt;truthy&lt;/em&gt; or &lt;em&gt;falsy&lt;/em&gt;. In addition to the actual &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; boolean values, using other values in a comparison statement will implicitly convert them to their boolean equivalent. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/41&#34;&gt;&amp;quot;truthy&amp;quot; and &amp;quot;falsy&amp;quot;&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;For reference:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;quot;Truthy&amp;quot; values: all objects and arrays (even if empty); non-zero numbers; non-empty strings; dates; functions&lt;/li&gt;
&lt;li&gt;&amp;quot;Falsy&amp;quot; values: &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, and empty strings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Note that the &amp;quot;empty object/array&amp;quot; behavior differs from Python, where those are considered &amp;quot;falsy&amp;quot;.)&lt;/p&gt;

&lt;p&gt;So, a comparison with an empty object like &lt;code&gt;if ({}) { console.log(&#39;Truthy!&#39;)}&lt;/code&gt; will actually convert to &lt;code&gt;true&lt;/code&gt; and print something, while a comparison with &lt;code&gt;null&lt;/code&gt; like &lt;code&gt;if (null) { console.log(&#39;Falsy!&#39;)}&lt;/code&gt; will convert to &lt;code&gt;false&lt;/code&gt; and not print anything.&lt;/p&gt;

&lt;p&gt;The boolean/comparison operators will all implicitly convert values to their boolean equivalent as well. A doubled negation operator is often used to convert a value to its boolean equivalent. For example, an empty string like &lt;code&gt;&#39;&#39;&lt;/code&gt; is falsy, so &lt;code&gt;!!&#39;&#39;&lt;/code&gt; would implicitly convert &lt;code&gt;&#39;&#39;&lt;/code&gt; to &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;!false&lt;/code&gt; to &lt;code&gt;true&lt;/code&gt;, and &lt;code&gt;!true&lt;/code&gt; to a final result of &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;JS also has two different comparison operators: &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt;. The double-equals &lt;code&gt;==&lt;/code&gt; operator does &lt;em&gt;loose comparisons&lt;/em&gt; that include implicit conversions of values. So, &lt;code&gt;0 == &#39;&#39;&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, because they will both end up being implicitly converted to &lt;code&gt;false&lt;/code&gt;, and &lt;code&gt;false&lt;/code&gt; is equal to &lt;code&gt;false&lt;/code&gt;. The triple-equals &lt;code&gt;===&lt;/code&gt; operator does &lt;em&gt;strict reference comparisons&lt;/em&gt; that check to see if the two values are literally identical. For objects and arrays, it compares to see if they are the same reference in memory. So, &lt;code&gt;{} === {}&lt;/code&gt; is false, because each of those is a separate new object reference.&lt;/p&gt;

&lt;p&gt;You should almost always prefer using &lt;code&gt;===&lt;/code&gt; strict reference comparisons to avoid unexpected implicit conversions. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/39&#34;&gt;comparisons and coercion&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&#34;functions&#34;&gt;Functions&lt;/h3&gt;

&lt;p&gt;JS has two different ways to define standalone functions: the &lt;code&gt;function&lt;/code&gt; keyword, and the &lt;code&gt;() =&amp;gt; {}&lt;/code&gt; &amp;quot;arrow function&amp;quot; syntax. They have some differences in behavior. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/33&#34;&gt;function syntax and behavior&lt;/a&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;function&lt;/code&gt; declarations are hoisted. Since arrow functions are assigned as variables, the declaration behavior is based on the keyword you use ( &lt;code&gt;const&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, or &lt;code&gt;var&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;function&lt;/code&gt; declarations create their own value for the &lt;code&gt;this&lt;/code&gt; keyword used inside. Arrow functions inherit the value of the &lt;code&gt;this&lt;/code&gt; keyword as it existed at the time and scope they were declared in.&lt;/li&gt;
&lt;li&gt;arrow functions can have optional parentheses if declared with only one parameter, and omitting curly braces adds an implicit &lt;code&gt;return&lt;/code&gt; statement: &lt;code&gt;const timesTwo = num =&amp;gt; num * 2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JS functions are very flexible with arguments and parameters. No matter how many parameters were declared, you can always call a function with more or fewer arguments. If I have &lt;code&gt;function myFunc(a, b, c) { }&lt;/code&gt;, but call it as &lt;code&gt;myFunc(1, 2)&lt;/code&gt;, then inside of the function &lt;code&gt;a === 1&lt;/code&gt;, &lt;code&gt;b === 2&lt;/code&gt;, and &lt;code&gt;c === undefined&lt;/code&gt; because we didn&#39;t provide a value when we called it. If I call it as &lt;code&gt;myFunc(1, 2, 3, 4)&lt;/code&gt;, then the &lt;code&gt;4&lt;/code&gt; argument is mostly ignored since we didn&#39;t declare a fourth parameter name. However, all function arguments can be accessed as an array-like value using the &lt;code&gt;arguments&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;Function parameters can have default values provided, which will be used if the incoming value is undefined. If we change the example to &lt;code&gt;function myFunc(a, b, c=42){ }&lt;/code&gt;, and call it as &lt;code&gt;myFunc(1, 2)&lt;/code&gt;, then &lt;code&gt;a === 1&lt;/code&gt;, &lt;code&gt;b === 2&lt;/code&gt;, and &lt;code&gt;c === 42&lt;/code&gt;. This is frequently used for initialization. Function arguments can also be &lt;em&gt;destructured&lt;/em&gt; - extracting specific fields from object and array parameters. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/51&#34;&gt;function declarations and arguments&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Since functions are just variables, they can be passed around like any other variable.&lt;/p&gt;

&lt;h2 id=&#34;js-in-depth&#34;&gt;JS in Depth&lt;/h2&gt;

&lt;h3 id=&#34;objects&#34;&gt;Objects&lt;/h3&gt;

&lt;p&gt;Object fields can be accessed with &lt;em&gt;dot notation&lt;/em&gt; (&lt;code&gt;obj.a.b.c&lt;/code&gt;) or &lt;em&gt;bracket notation&lt;/em&gt; (&lt;code&gt;obj[&amp;quot;a&amp;quot;][&amp;quot;b&amp;quot;[&amp;quot;c&amp;quot;]&lt;/code&gt;). Always use dot notation as long as the field names are known ahead of time. Use bracket notation if using a variable to look up a field ( &lt;code&gt;obj[key]&lt;/code&gt;), or if the field name is not a valid JS identifer ( &lt;code&gt;obj[&amp;quot;some-field&amp;quot;]&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Reading a field that doesn&#39;t exist returns &lt;code&gt;undefined&lt;/code&gt;, rather than throwing an error.&lt;/p&gt;

&lt;p&gt;Objects can be modified at any time. New fields can be added, existing fields can be reassigned, and fields can be deleted with &lt;code&gt;delete obj.field&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;ES6 introduced a shorthand syntax for declaring objects when a key:value pair should be added based on the name and value of an existing variable - you can omit the &lt;code&gt;: value&lt;/code&gt; portion:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// Shorthand syntax for declaring key/value pairs:
let x = 0,
  y = 1;

let es5Obj = { x: x, y: y };
// Create a key &#39;x&#39; whose value is the variable &#39;x&#39;
let es6Obj = { x, y };
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There&#39;s also a &lt;em&gt;computed property&lt;/em&gt; syntax that allows dynamically constructing keys based on the values of variables and expressions:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;let name = &#39;abc&#39;;

let es5Obj = {};
es5[name] = 123;

let es6Obj = {
  // Use the value of variable &#39;name&#39; as the property key


};
// {abc : 123, abc2 : 456}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Functions can be declared inside an object using &lt;code&gt;function&lt;/code&gt; or arrow functions as the values, or directly inline as &lt;code&gt;const obj = { someMethod() {} }&lt;/code&gt;. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/42&#34;&gt;Object literal syntax&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Objects can be &lt;em&gt;destructured&lt;/em&gt;, which is a shorthand for creating local variables based on the names of object fields. Destructuring statements can provide default values if that field is undefined, or change the local variable name that&#39;s created (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/49&#34;&gt;object destructuring and spreads&lt;/a&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;let obj1 = { a: 1, b: 2, c: 3, d: 4 };

// can create local variables the long way
let a = obj1.a;
let b = obj1.b;

// or destructure to shorten it:
let { a, b } = obj1;

// Local variables can be given different names:
let { a: differentA, c } = obj1;

// And have default values in case of undefined:
let { doesNotExist = 123 } = obj1;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;New objects can be created by using the &lt;em&gt;object spread&lt;/em&gt; operator to copy values onto a new object:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;let obj2 = { a: 1, b: 2, e: 5 };

let obj3 = { ...obj2, a: 99 };
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are static methods on the &lt;code&gt;Object&lt;/code&gt; built-in type that allow getting all of the keys or values as arrays (&lt;code&gt;Object.keys(someObj)&lt;/code&gt;), or an array of key/value pairs as 2-element arrays (&lt;code&gt;Object.entries(somObj)&lt;/code&gt;). &lt;code&gt;Object.assign(target, src1, src1)&lt;/code&gt; can be used to mutate existing objects by copying properties, or create new objects by passing an empty object as the &lt;code&gt;target&lt;/code&gt;. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/43&#34;&gt;Object static methods&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&#34;arrays&#34;&gt;Arrays&lt;/h3&gt;

&lt;p&gt;Arrays are 0-indexed, but can be &lt;em&gt;sparse&lt;/em&gt; - any index can be assigned at any time (&lt;code&gt;arr[97] = &amp;quot;stuff&amp;quot;&lt;/code&gt;). Arrays may hold any value and a mixture of different types of values. Like with objects, accessing a non-existing array index returns &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Like with objects, you can use destructuring to read values from arrays (&lt;code&gt;const [a, , c] = [&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;]&lt;/code&gt;), and spread operators to create arrays (&lt;code&gt;const arr3 = [...arr1, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;, ...arr2, &amp;quot;d&amp;quot;]&lt;/code&gt;). (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/32&#34;&gt;array syntax&lt;/a&gt;, &lt;a href=&#34;https://blog.isquaredsoftware.com/persentations/2019-05-js-for-java-devs/#/48&#34;&gt;array destructuring&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Arrays are actually objects as well, and have numerous methods built in for various purposes. Some of these methods mutate the existing array, others return new arrays or other values. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/44&#34;&gt;array methods&lt;/a&gt;, &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/45&#34;&gt;array iteration methods&lt;/a&gt;, &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/47&#34;&gt;array searching&lt;/a&gt;)&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Arguments&lt;/th&gt;
&lt;th&gt;Returns&lt;/th&gt;
&lt;th&gt;Mutates&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;slice()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Copies an array subset&lt;/td&gt;
&lt;td&gt;Indices to copy&lt;/td&gt;
&lt;td&gt;A new array&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;concat()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Creates array with more values&lt;/td&gt;
&lt;td&gt;New values/arrays to add&lt;/td&gt;
&lt;td&gt;A new array&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;splice()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inserts/deletes values&lt;/td&gt;
&lt;td&gt;Index to mutate/delete, values to insert&lt;/td&gt;
&lt;td&gt;Items removed&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;join()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stringifies array contents&lt;/td&gt;
&lt;td&gt;String used to separate items&lt;/td&gt;
&lt;td&gt;A new string&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;push()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inserts new items at end of array&lt;/td&gt;
&lt;td&gt;Items to insert&lt;/td&gt;
&lt;td&gt;Array size after&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pop()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes last item from array&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Last array item&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;unshift()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inserts new items at start of array&lt;/td&gt;
&lt;td&gt;Items to insert&lt;/td&gt;
&lt;td&gt;Array size after&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;shift()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes first item from array&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;First array item&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sort()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sorts existing array&lt;/td&gt;
&lt;td&gt;Callback to compare two items&lt;/td&gt;
&lt;td&gt;Existing array reference&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;reverse()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reverses order of items in array&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Existing array reference&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;map()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;New array by transforming values&lt;/td&gt;
&lt;td&gt;Callback to transform one item&lt;/td&gt;
&lt;td&gt;New array with callback return values&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;New array with values matching comparison&lt;/td&gt;
&lt;td&gt;Callback to compare one item&lt;/td&gt;
&lt;td&gt;New array with original items where callback returned true&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;forEach()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;General iteration for side effects&lt;/td&gt;
&lt;td&gt;Callback to run logic for one item&lt;/td&gt;
&lt;td&gt;Nothing&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;reduce()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Calculates one result value based on all items&lt;/td&gt;
&lt;td&gt;Callback to accumulate running result&lt;/td&gt;
&lt;td&gt;Final callback result value&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;indexOf()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds index of exact value match&lt;/td&gt;
&lt;td&gt;Value to search for&lt;/td&gt;
&lt;td&gt;index or -1&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;includes()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if exact value is in array&lt;/td&gt;
&lt;td&gt;Value to search fo&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;find()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Find item by comparison&lt;/td&gt;
&lt;td&gt;Callback to compare one item&lt;/td&gt;
&lt;td&gt;First match or undefined&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;findIndex()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Find index of item by comparison&lt;/td&gt;
&lt;td&gt;Callback to compare one item&lt;/td&gt;
&lt;td&gt;index or -1&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;some()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if any items match comparison&lt;/td&gt;
&lt;td&gt;Callback to compare one item&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;&lt;code&gt;every()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if all items match comparison&lt;/td&gt;
&lt;td&gt;Callback to compare one item&lt;/td&gt;
&lt;td&gt;boolean&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;To emphasize, &lt;code&gt;array.sort()&lt;/code&gt; and &lt;code&gt;array.reverse()&lt;/code&gt; &lt;strong&gt;mutate the existing array!&lt;/strong&gt;. This can be very surprising if you&#39;re not expecting it. In many cases it&#39;s a good idea to make a copy of an array using &lt;code&gt;[...arr]&lt;/code&gt; or &lt;code&gt;arr.slice()&lt;/code&gt; first and then sort/reverse the copy, especially if you&#39;re using something like React or Redux.&lt;/p&gt;

&lt;p&gt;The core iteration methods each have a different semantic meaning and purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;map()&lt;/code&gt;: creates a new array, with the same size as the original array, whose values are based on a transformation of the original values

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;const doubledNumbers = [1, 2, 3].map(num =&amp;gt; num * 2)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;filter()&lt;/code&gt;: creates a new array, with some of the values from the original, based on values where the comparison returned &lt;code&gt;true&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;const evenNumbers = [1, 2, 3].filter(num =&amp;gt; num % 2 === 0)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;forEach()&lt;/code&gt;: general iteration over the array, usually to produce side effects

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;[1, 2, 3].forEach(num =&amp;gt; console.log(num))&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;reduce()&lt;/code&gt;: calculates a single result value based on &amp;quot;accumulating&amp;quot; a running result at each step, plus a starting value

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;const total = [1, 2, 3].reduce( (previousResult, currentValue) =&amp;gt; previousResult + currentValue, 0)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;scoping-and-closures&#34;&gt;Scoping and Closures&lt;/h3&gt;

&lt;p&gt;As mentioned above, the &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt;, and &lt;code&gt;var&lt;/code&gt; keywords differ in their scoping behavior. &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are &lt;em&gt;block-scoped&lt;/em&gt; - they only exist within the curly braces block where they&#39;re declared, and the same variable name can be reused and &lt;em&gt;shadowed&lt;/em&gt; inside of nested blocks. &lt;code&gt;var&lt;/code&gt; is &lt;em&gt;function-scoped&lt;/em&gt; - no matter where it&#39;s used, the declaration is &lt;em&gt;hoisted&lt;/em&gt; to act as if it was written on the first line of the function it&#39;s inside, and reusing the same name will override the earlier declaration. The &lt;code&gt;function&lt;/code&gt; declaration keyword is also hoisted. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/37&#34;&gt;variable scope and hoisting&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There is a top level &amp;quot;global object&amp;quot; that can always be referenced, and any variables declared in the top-level global scope using &lt;code&gt;var&lt;/code&gt; become fields on that object. In a browser, the object is &lt;code&gt;window&lt;/code&gt;, and under Node, it&#39;s &lt;code&gt;global&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Code inside functions can reference variables outside functions, because those variables are in an outer scope. Functions can be declared inside of functions, and &lt;em&gt;close over&lt;/em&gt; variables by referencing them. A nested function that references a variable in the parent scope is called a &lt;em&gt;closure&lt;/em&gt;. This allows nested functions to continue to refer to and modify variables long after the outer function has finished running. This is frequently used when passing &lt;em&gt;callback functions&lt;/em&gt; for use as event handlers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding closures is a critical part of mastering JavaScript behavior.&lt;/strong&gt; (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/52&#34;&gt;functions and closures&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// Functions can create and return functions
function createPrintName() {
  let name = &#39;Mark&#39;;

  function printName() {
    console.log(name);
  }

  return printName;
}

// Functions can capture references to values.
// These are called &amp;quot;closures&amp;quot;.
function makeCounter() {
  let timesCalled = 0;
  return function counter() {
    timesCalled++;
    console.log(`Times called: ${timesCalled}`);
  };
}

const actualCounter = makeCounter();
actualCounter(); // &amp;quot;Times called: 1&amp;quot;
actualCounter(); // &amp;quot;Times called: 2&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;functions-and-this&#34;&gt;Functions and &lt;code&gt;this&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;The behavior of the &lt;code&gt;this&lt;/code&gt; keyword in JS is one of the most confusing and difficult topics to grasp, especially if you are coming from a language like C# or Java.&lt;/p&gt;

&lt;p&gt;Unlike other languages, &lt;strong&gt;the value of &lt;code&gt;this&lt;/code&gt; can point to different references depending on how a function is declared and what syntax was used to call it&lt;/strong&gt;. Instead of always pointing to a specific instance of a class, what &lt;code&gt;this&lt;/code&gt; points to is based on the &lt;em&gt;execution context&lt;/em&gt; of a function.&lt;/p&gt;

&lt;p&gt;This is a long and complicated topic, so I&#39;ll summarize it briefly here and suggest reading up on it further.&lt;/p&gt;

&lt;p&gt;There are four ways to call a function in JS, which each have a different effect on the value of &lt;code&gt;this&lt;/code&gt; inside of the function (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/54&#34;&gt;understanding &lt;code&gt;this&lt;/code&gt;&lt;/a&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;quot;Function invocation&amp;quot;: &lt;code&gt;someFunction(1, 2)&lt;/code&gt; (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/55&#34;&gt;function invocation&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;this&lt;/code&gt; points to &lt;code&gt;undefined&lt;/code&gt; or the global object, based on use of &lt;em&gt;strict mode&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Method invocation&amp;quot;: &lt;code&gt;someObject.someFunction(1, 2)&lt;/code&gt; (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/56&#34;&gt;method invocation&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;this&lt;/code&gt; points to &lt;code&gt;someObject&lt;/code&gt; because of the dot operator&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Constructor invocation&amp;quot;: &lt;code&gt;new SomeFunction(1, 2)&lt;/code&gt; (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/57&#34;&gt;constructor invocation&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;this&lt;/code&gt; points to the new function instance&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Indirect invocation&amp;quot;: &lt;code&gt;someFunction.call(thisArg, 1, 2)&lt;/code&gt; or &lt;code&gt;someFunction.apply(thisArg, [1, 2])&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;this&lt;/code&gt; points to the first argument of &lt;code&gt;.call()&lt;/code&gt; or &lt;code&gt;.apply()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Functions can be &lt;em&gt;bound&lt;/em&gt; to create a new function with pre-fixed values for some of their arguments, including forcing the value of &lt;code&gt;this&lt;/code&gt;. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/58&#34;&gt;indirect invocation and binding&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Arrow functions inherit the value of &lt;code&gt;this&lt;/code&gt; at the time they were defined (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/59&#34;&gt;arrow functions and &lt;code&gt;this&lt;/code&gt;&lt;/a&gt;)&lt;/p&gt;

&lt;h3 id=&#34;classes-and-prototypes&#34;&gt;Classes and Prototypes&lt;/h3&gt;

&lt;p&gt;JS inheritance is unlike other most major languages - it&#39;s based on a system of &lt;em&gt;prototypes&lt;/em&gt; for objects, and is known as &lt;em&gt;prototypal inheritance&lt;/em&gt;. Loosely put, inheritance is dynamic and determined at runtime by tracing field lookups up a chain of references for a given object, instead of being defined strictly at definition time like in Java or C#. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/62&#34;&gt;prototypal inheritance&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// Define a function to act as a &amp;quot;class&amp;quot;
function Animal(name, isAwake) {
  this.name = name;
  this.isAwake = isAwake;
}

// Create methods by adding functions to the &amp;quot;prototype&amp;quot;
Animal.prototype.wakeUp = function () {
  this.isAwake = true;
};

Animal.prototype.sleep = function () {
  this.isAwake = false;
};

// Create an instance
let jinx = new Animal(&#39;Jinx&#39;, true);

// Call an instance method
jinx.sleep();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;ES6 added an actual &lt;code&gt;class&lt;/code&gt; keyword to the language, but it is effectively syntax sugar over the existing prototypal inheritance behavior (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/63&#34;&gt;classes&lt;/a&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;class Animal {
  constructor(name, isAwake) {
    this.name = name;
    this.isAwake = isAwake;
  }

  wakeUp() {
    this.isAwake = true;
  }

  sleep() {
    this.isAwake = false;
  }
}

class Dog extends Animal {
  constructor(name, isAwake, isWaggingTail) {
    super(name, isAwake);
    this.isWaggingTail = isWaggingTail;
  }

  bark() {
    console.log(&#39;Woof! Woof!&#39;);
  }
}

let spot = new Dog(&#39;Spot&#39;, true, false);
spot.sleep();
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;async&#34;&gt;Async&lt;/h2&gt;

&lt;h3 id=&#34;timers-and-the-event-loop&#34;&gt;Timers and the Event Loop&lt;/h3&gt;

&lt;p&gt;JS execution is based on a &lt;em&gt;single-threaded &lt;strong&gt;event loop&lt;/strong&gt; + queue&lt;/em&gt;. Conceptually, the behavior is &lt;code&gt;while(queue.waitForMessage()) queue.processNextMessage()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Events are added to the queue, and have JS code attached. This includes mouse events, timers, network requests, and much more. The event loop pops the next event off the queue, and &lt;strong&gt;executes the entire attached code to completion&lt;/strong&gt;. The currently executing script &lt;strong&gt;cannot be interrupted&lt;/strong&gt;. The script may start timers, which will add events with scripts to the queue for later execution.&lt;/p&gt;

&lt;p&gt;While there is only one JS execution thread, the browser itself may add events to the queue while code is executing. Rather than blocking for async requests, they will schedule events when they complete.&lt;/p&gt;

&lt;p&gt;Note that if you have an infinite loop in your code, &lt;strong&gt;the event loop is &amp;quot;blocked&amp;quot; and cannot move on to process the next event&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;JS logic relies heavily on &lt;em&gt;callbacks&lt;/em&gt; - passing a function reference to be called and executed at some future point in time. Callback usage can be synchronous or asynchronous depending on the use case. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/67&#34;&gt;callbacks and timers&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;JS provides two core functions for scheduling async logic: &lt;code&gt;setTimeout(callback, ms)&lt;/code&gt;, which runs the callback function once, and &lt;code&gt;setInterval(callback, ms)&lt;/code&gt;, which runs the callback repeatedly. Both functions return a unique ID value that can be used to cancel the queued timer via &lt;code&gt;clearTimeout()&lt;/code&gt; or &lt;code&gt;clearInterval()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the JS event loop is critical to understanding how to use async logic in JS!&lt;/strong&gt; See the video &lt;a href=&#34;https://youtu.be/8aGhZQkoFbQ&#34;&gt;What the heck is the event loop anyway?&lt;/a&gt; for an excellent explanation, as well as &lt;a href=&#34;http://latentflip.com/loupe/&#34;&gt;this accompanying interactive event loop visualization tool&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&#34;promises&#34;&gt;Promises&lt;/h3&gt;

&lt;p&gt;Nested async calls often result in a &amp;quot;callback pyramid of doom&amp;quot;:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;fetchData(&#39;/endpoint1&#39;, (result1) =&amp;gt; {
  fetchData(&#39;/endpoint2&#39;, (result2) =&amp;gt; {
    fetchData(&#39;/endpoint3&#39;, (result3) =&amp;gt; {
      // do something with results 1 through 3
    });
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This also makes error handling very difficult.&lt;/p&gt;

&lt;p&gt;The JS &lt;code&gt;Promise&lt;/code&gt; data type provides a structured way to handle future async results (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/70&#34;&gt;promise basics&lt;/a&gt;. Promises are objects can be in one of three states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Pending&lt;/em&gt;: created, but there is no result yet&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Fulfilled&lt;/em&gt;: completed, with a positive/successful result&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Rejected&lt;/em&gt;: completed, with an error result&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A Promise has &lt;em&gt;settled&lt;/em&gt; or &lt;em&gt;resolved&lt;/em&gt; once it is either fulfilled or rejected.&lt;/p&gt;

&lt;p&gt;Promises can be &lt;em&gt;chained&lt;/em&gt; using &lt;code&gt;somePromise.then(callback)&lt;/code&gt; and &lt;code&gt;somePromise.catch(callback)&lt;/code&gt;. When &lt;code&gt;somePromise&lt;/code&gt; resolves, any provided chained callbacks will be run - &lt;code&gt;.then()&lt;/code&gt; callbacks if it fulfilled, or &lt;code&gt;.catch()&lt;/code&gt; callbacks if it rejected. Callbacks can even be chained after the promise has resolved, in which case they will be executed almost immediately.&lt;/p&gt;

&lt;p&gt;Promise chains effectively form a pipeline. Each &lt;code&gt;.then()&lt;/code&gt; or &lt;code&gt;.catch()&lt;/code&gt; returns a new promise. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/72&#34;&gt;creating and chaining promises&lt;/a&gt;, &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/74&#34;&gt;combining and resolving promises&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;let promise1 = new Promise((resolve, reject) =&amp;gt; {
  // This callback executes synchronously, immediately
  // Could &amp;quot;resolve&amp;quot; the promise with a value:
  resolve(&#39;a&#39;);
});

promise1
  .then((firstValue) =&amp;gt; {
    // &amp;quot;a&amp;quot;
    return &#39;b&#39;;
  })
  .then((secondValue) =&amp;gt; {
    // &amp;quot;b&amp;quot;
    // _Not_ returning a value returns `undefined`
  })
  .then((thirdValue) =&amp;gt; {
    // undefined
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Inside a promise callback, you can run whatever calculations you want, but you can only do 3 things to complete the logic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Return a value: resolves the promise successfully, with that value. Note that returning nothing or &lt;code&gt;undefined&lt;/code&gt; is the same as resolving the promise successfully with &lt;code&gt;undefined&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Return another promise. The new promise for the callback will resolve or reject based on the promise you returned.&lt;/li&gt;
&lt;li&gt;Throw an error. This rejects the promise, with that error.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;async-await-syntax-for-promises&#34;&gt;&lt;code&gt;async/await&lt;/code&gt; Syntax for Promises&lt;/h3&gt;

&lt;p&gt;Chaining Promises can also be difficult. The newer &lt;code&gt;async/await&lt;/code&gt; syntax lets you write Promise-handling logic with what appears to be synchronous-style syntax, including use of &lt;code&gt;try/catch&lt;/code&gt; for handling errors.&lt;/p&gt;

&lt;p&gt;A function must be declared using the &lt;code&gt;async&lt;/code&gt; keyword in order to use the &lt;code&gt;await&lt;/code&gt; keyword inside. Every &lt;code&gt;async&lt;/code&gt; function then automatically returns a Promise with whatever value is returned. Rejected promises in an async &lt;code&gt;try/catch&lt;/code&gt; will jump to the &lt;code&gt;catch&lt;/code&gt; block. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/75&#34;&gt;&lt;code&gt;async/await&lt;/code&gt;&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// This function:
function function1() {
  let resultPromise = Promise.resolve(42);
  return resultPromise;
}

// Is the same as this function:
async function function2() {
  return 42; // converted to a promise!
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Overall, &lt;code&gt;async/await&lt;/code&gt; syntax is much nicer to read than promise chains, and should usually be preferred:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// This promise chain:
function fetchStuff() {
  return fetchData(&#39;/endpoint1&#39;)
    .then((result) =&amp;gt; {
      return firstProcessStep(result);
    })
    .then((processedResult) =&amp;gt; {
      console.log(`Processed result: ${processedResult}`);
      return processedResult;
    })
    .catch((err) =&amp;gt; {
      console.error(&#39;PANIC!&#39;, err);
    });
}

// Can convert to:
async function alsoFetchStuff() {
  try {
    let result = await fetchData(&#39;/endpoint1&#39;);
    let processedResult = firstProcessStep(result);
    console.log(`Processed result: ${processedResult}`);
    return processedResult;
  } catch (err) {
    console.error(&#39;PANIC!&#39;, err);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;other-topics&#34;&gt;Other Topics&lt;/h2&gt;

&lt;h3 id=&#34;js-module-formats&#34;&gt;JS Module Formats&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;ES Module&lt;/em&gt; format is now the standard for writing most new code. &lt;em&gt;CommonJS modules&lt;/em&gt; are still widely used with Node and as a publishing format. For details and examples of the various module formats, see &lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/#javascript-module-formats&#34;&gt;Client Development and Deployment: JS Module Formats&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&#34;regular-expressions&#34;&gt;Regular Expressions&lt;/h3&gt;

&lt;p&gt;JS has regular expressions available for complex text matching. Regexes can be declared using slashes, like &lt;code&gt;/Have a good (day|afternoon|evening)/&lt;/code&gt;. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/100&#34;&gt;regular expressions&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Regex objects have methods like &lt;code&gt;.test(str)&lt;/code&gt; and &lt;code&gt;.match(str)&lt;/code&gt;, and can be passed to some string methods as well ( &lt;code&gt;&amp;quot;Hello world!&amp;quot;.replace(/world/, &#39;dog&#39;)&lt;/code&gt;).&lt;/p&gt;

&lt;h3 id=&#34;immutability&#34;&gt;Immutability&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Mutation&lt;/em&gt; means changing the contents of an existing object or array in memory. For example, &lt;code&gt;obj1.a = 42&lt;/code&gt; mutates the existing object pointed to by &lt;code&gt;obj1&lt;/code&gt;, and &lt;code&gt;arr1.push(&#39;abcd&#39;)&lt;/code&gt; mutates the existing array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Immutability&lt;/em&gt; is the concept of updating data by copying existing values and modifying the copies, rather than mutating the original values. JS is inherently a mutable language, so you have to explicitly write logic to make updates immutably. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/101&#34;&gt;immutability&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;For objects, this usually is done via the object spread operator:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;let updatedObj2 = {
  ...obj2, // copy all fields from obj2,
  nested: {
    // provide a new `nested` value
    ...obj2.nested, // copy fields from `obj2.nested`
    d: 123, // but overwrite `obj2.nested.d` in this copy
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Arrays can be copied using the array spread operator or &lt;code&gt;array.slice()&lt;/code&gt;. See the array methods table above for details on which array methods mutate the existing array, vs methods that return a new array.&lt;/p&gt;

&lt;p&gt;There are many utility libraries that can help with immutable updates, but by far the best is &lt;a href=&#34;https://immerjs.github.io/immer/docs/introduction&#34;&gt;Immer&lt;/a&gt;. Immer provides a &lt;code&gt;produce&lt;/code&gt; function that will wrap your original data in a &lt;code&gt;Proxy&lt;/code&gt; object and let you &amp;quot;mutate&amp;quot; the value in a callback, but then converts all the mutations into safe immutable updates and returns the result:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// hand-written immutable update:
function toggleTodo(todos, index) {
  return todos.map((todo, i) =&amp;gt; {
    // Keep the items that aren&#39;t changing
    if (i !== index) return todo;

    // Return a new copied object for the item that is changing
    return { ...todo, completed: !todo.completed };
  });
}

// simpler with Immer because we can &amp;quot;mutate&amp;quot;:
import produce from &#39;immer&#39;;

function toggleTodo(todos, index) {
  return produce(todos, (draftTodos) =&amp;gt; {
    const todo = draftTodos[index];
    todo.completed = !todo.completed; // Safe &amp;quot;mutation&amp;quot;!
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;lodash&#34;&gt;Lodash&lt;/h3&gt;

&lt;p&gt;JS has a small and limited standard library built in. Lodash is a separate library of utility functions, and is one of the most widely used libraries in the JS ecosystem. It provides dozens of utility functions for everything from array and object operations, to working with functions, to checking the type of a value, to converting strings between different formats. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/103&#34;&gt;Lodash&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// Arrays
_.difference([&#39;a, b&#39;], [&#39;c&#39;, &#39;b&#39;]); // [&amp;quot;a&amp;quot;]
_.head([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]); // &amp;quot;a&amp;quot;
_.tail([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]); // &amp;quot;c&amp;quot;
_.intersection([&#39;a&#39;, &#39;b&#39;], [&#39;b&#39;, &#39;c&#39;]); // [&amp;quot;b&amp;quot;]

// &amp;quot;Collections&amp;quot; (objects and arrays)
_.groupBy([6.1, 4.2, 6.3], Math.floor);
// =&amp;gt; { &#39;4&#39;: [4.2], &#39;6&#39;: [6.1, 6.3] }

let items = [
  { n: &#39;f&#39;, a: 48 },
  { n: &#39;b&#39;, a: 36 },
  { n: &#39;w&#39;, a: 38 },
];
let sortedItems = _.sortBy(items, &#39;a&#39;);
// =&amp;gt; [{n: &amp;quot;b&amp;quot;, a:36}, {n: &amp;quot;w&amp;quot;, a: 38}, {n: &amp;quot;f&amp;quot;, a:48}]

// Objects
let obj1 = { a: 2, b: 3, c: 7 };
_.mapValues(obj1, (val) =&amp;gt; val * 2); // {a : 4, b : 6, c : 14}

_.omit(obj1, [&#39;b&#39;]); // {a : 2, c : 7}
_.pick(obj1, [&#39;b&#39;, &#39;c&#39;]); // {b : 3, c: 7}

// Strings
_.camelCase(&#39;Foo Bar&#39;); // &amp;quot;fooBar&amp;quot;
_.kebabCase(&#39;Foo Bar&#39;); // &amp;quot;foo-bar&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;dom&#34;&gt;DOM&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/#html&#34;&gt;HTML&lt;/a&gt; is a text document format, organized into a hierarchy of nested &lt;em&gt;tags&lt;/em&gt; like &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, that represents the desired structure and content of a web page.&lt;/p&gt;

&lt;p&gt;Browsers download an HTML file, and parse the HTML tags. They then create a set of internal data structures that match the requested page content, and use that to lay out and draw the actual pixels on screen.&lt;/p&gt;

&lt;p&gt;Browsers also expose a live representation of the current page content to JS. This is known as the &lt;em&gt;Document Object Model (DOM)&lt;/em&gt;. While every browser has its own different internal data structures for a page, the DOM is a standardized set of APIs for interacting with the content of a page. The DOM APIs enable JS code to create, read, modify, and delete the actual contents of a page, dynamically, after the initial HTML has been parsed and the page was loaded.&lt;/p&gt;

&lt;p&gt;The DOM spec defines classes that correspond to each HTML element type. For example, a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag, when parsed, will result in an &lt;code&gt;HTMLDivElement&lt;/code&gt; class instance being created and added to the DOM. Each instance is called a &lt;em&gt;DOM node&lt;/em&gt;, because the DOM contents form a tree.&lt;/p&gt;

&lt;p&gt;Different DOM classes support different methods - an &lt;code&gt;HTMLInputElement&lt;/code&gt; instance has different methods available than an &lt;code&gt;HTMLDivElement&lt;/code&gt; instance, but all DOM node instances share a common core set of base methods.&lt;/p&gt;

&lt;h3 id=&#34;dom-query-apis&#34;&gt;DOM Query APIs&lt;/h3&gt;

&lt;p&gt;The DOM API allows querying for nodes based on &lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/#css-selectors&#34;&gt;selectors&lt;/a&gt;, such as the type of tag, ID attribute, classnames, node relational structure, and more. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/108&#34;&gt;DOM query and manipulation&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The root element for a page is globally accessible via the global &lt;code&gt;document&lt;/code&gt; object. Most queries are run against &lt;code&gt;document&lt;/code&gt; to find nodes anywhere inside a page.&lt;/p&gt;

&lt;p&gt;The primary query APIs are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;getElementById()&lt;/code&gt;: finds a DOM node based on an ID attribute string. (Note that the ID string should be provided without a &lt;code&gt;&#39;#&#39;&lt;/code&gt; prefix here, unlike other places where an actual selector is being used to query)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;querySelectorAll()&lt;/code&gt;: finds all DOM nodes that match the provided CSS selector query&lt;/li&gt;
&lt;li&gt;&lt;code&gt;querySelector()&lt;/code&gt;: finds the first DOM node that matches the provided CSS selector query&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These same query APIs also exist on the DOM node subclasses, so you can run &lt;code&gt;someNode.querySelectorAll()&lt;/code&gt; to scope a search to that particular portion of the page&#39;s DOM tree.&lt;/p&gt;

&lt;p&gt;Note that &lt;code&gt;querySelectorAll()&lt;/code&gt; returns a &lt;code&gt;NodeList&lt;/code&gt; object. This is an &lt;em&gt;array-like&lt;/em&gt; object. It implements a couple array-type methods like &lt;code&gt;.forEach()&lt;/code&gt;, but is not an actual array. It&#39;s common to convert a &lt;code&gt;NodeList&lt;/code&gt; result into an actual array before doing further work with the query results.&lt;/p&gt;

&lt;p&gt;Other query methods like &lt;code&gt;getElementsByName&lt;/code&gt; also return a &lt;code&gt;NodeList&lt;/code&gt;, but those results are &amp;quot;live&amp;quot; views whose contents automatically change as the DOM is updated. This behavior can be confusing if you&#39;re not ready for it.&lt;/p&gt;

&lt;h3 id=&#34;dom-manipulation&#34;&gt;DOM Manipulation&lt;/h3&gt;

&lt;p&gt;DOM nodes support a wide variety of manipulation operations.&lt;/p&gt;

&lt;p&gt;New DOM nodes can be created with &lt;code&gt;document.createElement(&#39;p&#39;)&lt;/code&gt;, which returns an instance of the requested node type, or copied with &lt;code&gt;.cloneNode()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;DOM nodes have &lt;code&gt;.innerHTML&lt;/code&gt; and &lt;code&gt;.innerText&lt;/code&gt; properties, which allow reading and writing the entire contents of a node at once. Input nodes typically have properties like &lt;code&gt;.name&lt;/code&gt; and &lt;code&gt;.value&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Nodes have a &lt;code&gt;.classlist&lt;/code&gt; property, which is an object that supports adding, removing, and toggling the existence of individual CSS classnames on that node (&lt;code&gt;divNode.classlist.toggle(&#39;active&#39;)&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Nodes have a &lt;code&gt;.style&lt;/code&gt; property that allows reading and mutating any of the style-related properties, including values that were defined using CSS (&lt;code&gt;divNode.style.backgroundColor = &#39;red&#39;&lt;/code&gt;). Unlike CSS, the style property names are &lt;code&gt;camelCased&lt;/code&gt; instead of &lt;code&gt;kebab-cased&lt;/code&gt;, because that matches JS naming conventions.&lt;/p&gt;

&lt;p&gt;Nodes have properties that point to related nodes in the tree: &lt;code&gt;.children&lt;/code&gt;, &lt;code&gt;.firstChild/lastChild&lt;/code&gt;, &lt;code&gt;.nextSibling/previousSibling&lt;/code&gt;, and &lt;code&gt;.parentNode&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Nodes can be inserted and moved around with with &lt;code&gt;.appendChild()&lt;/code&gt;, &lt;code&gt;.insertBefore()/insertAfter()&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&#34;event-listeners&#34;&gt;Event Listeners&lt;/h3&gt;

&lt;p&gt;DOM nodes implement an &lt;em&gt;event listener&lt;/em&gt; interface, which looks like &lt;code&gt;node.addEventListener(eventName, callback)&lt;/code&gt;. There&#39;s a wide variety of available events that will be triggered by the browser as the user interacts, such as &lt;code&gt;&#39;click&#39;&lt;/code&gt;, &lt;code&gt;&#39;mousemove&#39;&lt;/code&gt;, and &lt;code&gt;&#39;keydown&#39;&lt;/code&gt;. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/109&#34;&gt;DOM event handling&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Event handlers receive an &lt;em&gt;event object&lt;/em&gt; with numerous fields describing the current event. Inside of an event handler callback, &lt;code&gt;this&lt;/code&gt; will point to the actual DOM node as long as you declared the callback with &lt;code&gt;function&lt;/code&gt; (arrow functions always use the same &lt;code&gt;this&lt;/code&gt; value from the scope where they were defined).&lt;/p&gt;

&lt;p&gt;When a DOM event is triggered, it &lt;em&gt;bubbles&lt;/em&gt; upwards from the original target node, through all of its parent nodes, to the root document, firing any matching event handlers along the way. After the event has reached the root, it then runs back down from the root to the original node, known as the &lt;em&gt;capturing&lt;/em&gt; phase.&lt;/p&gt;

&lt;p&gt;Because events bubble up, it&#39;s possible to add a single event listener on some parent node that catches all events of a certain type on any children. This pattern is known as &lt;em&gt;event delegation&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Any event handler may cancel the rest of the handler processing by calling &lt;code&gt;e.stopPropagation()&lt;/code&gt;. The browser also often has default behavior that will be run regardless of any user-provided listeners, which can be canceled with with &lt;code&gt;e.preventDefault()&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&#34;jquery&#34;&gt;jQuery&lt;/h3&gt;

&lt;p&gt;For many years, the DOM APIs were poorly defined, had widely varying support between browsers, and had limited query capabilities built in. The community created many libraries to fill in these gaps and provide common capabilities across browsers. jQuery became the most popular DOM manipulation library by far. Many of its capabilities have been added to the DOM APIs themselves, and the need for jQuery has lessened as the ecosystem has evolved, but it&#39;s still one of the most widely used JS libraries. (slides: &lt;a href=&#34;https://blog.isquaredsoftware.com/presentations/2019-05-js-for-java-devs/#/115&#34;&gt;jQuery examples&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;jQuery is an abstraction layer for querying nodes from the DOM and quickly manipulating them via chained operator functions. It also has utilities for interacting with inputs, creating DOM nodes from HTML strings, provides a nicer abstraction over the browser&#39;s built-in APIs for making AJAX requests, adds some animation capabilities, and has a plugin system that allows developers to extend its capabilities.&lt;/p&gt;

&lt;p&gt;jQuery is not a framework for developing entire applications - it&#39;s best suited for adding interactivity to an existing static or server-rendered web page. jQuery is not normally needed in today&#39;s modern client-rendered web app frameworks like React or Vue, because those frameworks take care of creating and updating the DOM for you, and using jQuery would interfere with their operations.&lt;/p&gt;

&lt;p&gt;Once loaded, the jQuery API is globally accessible as a variable named &lt;code&gt;$&lt;/code&gt;. DOM queries are run by passing a selector, like &lt;code&gt;$(&amp;quot;#demo .content&amp;quot;)&lt;/code&gt;, which returns an array-like object with numerous methods that can be chained. It&#39;s a common practice to prefix jQuery result object variable names with &lt;code&gt;$&lt;/code&gt;, like &lt;code&gt;$demo.css(&amp;quot;backgroundColor&amp;quot;, &amp;quot;green&amp;quot;).slideUp(500)&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&#34;further-resources&#34;&gt;Further Resources&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JS Overviews and Tutorials&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript&#34;&gt;MDN JavaScript docs&lt;/a&gt;: extensive tutorials and reference material on all aspects of JS&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.freecodecamp.org/&#34;&gt;FreeCodeCamp tutorials&lt;/a&gt;: beginner-focused project-based tutorials&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://javascript.info/&#34;&gt;The Modern JS Tutorial&lt;/a&gt;: topic-based intros to specific aspects of JS and DOM syntax&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://2ality.com/index.html&#34;&gt;2ality: JS books and articles&lt;/a&gt;: in-depth articles and books that cover JS syntax and behavior in fine detail, including articles that summarize the new features in each ES spec revision&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2019/05/presentation-js-for-java-devs/&#34;&gt;JS for Java Developers slides&lt;/a&gt;: a cheatsheet-style summary of JS syntax, concepts, and ecosystem tools&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.taniarascia.com/tags/javascript&#34;&gt;Tania Rascia&#39;s JS tutorials&lt;/a&gt;: a broad set of tutorials that cover JS topics such as syntax, events, classes, functions, async, and more&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.jetbrains.com/lp/javascript-25/&#34;&gt;JS 25th Anniversary milestones timeline&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The &lt;code&gt;this&lt;/code&gt; keyword&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dmitripavlutin.com/gentle-explanation-of-this-in-javascript/&#34;&gt;A Gentle Explanation of &lt;code&gt;this&lt;/code&gt; in JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/&#34;&gt;Understanding JS Function Invocation and &lt;code&gt;this&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://zellwk.com/blog/this/&#34;&gt;&lt;code&gt;this&lt;/code&gt; in JS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Array Methods&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dev.to/andrew565/which-array-function-when&#34;&gt;Which Array Method When?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://doesitmutate.xyz/&#34;&gt;Does It Mutate?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://jesseduffield.com/array-functions-and-the-rule-of-least-power/&#34;&gt;Array Functions and the Rule of Least Power&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JS Event Loop and Async&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.taniarascia.com/asynchronous-javascript-event-loop-callbacks-promises-async-await/&#34;&gt;Understanding the Event Loop, Callbacks, Promises, and Async/Await in JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://youtu.be/8aGhZQkoFbQ&#34;&gt;What the heck is the event loop anyway?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://latentflip.com/loupe/&#34;&gt;Loupe: Event loop interactive explorer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.jsv9000.app/&#34;&gt;JS Visualizer 9000: interactive event loop and async task queue explorer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Other Topics&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://daveceddia.com/javascript-references/&#34;&gt;A Visual Guide to References in JS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://daveceddia.com/react-redux-immutability-guide/&#34;&gt;Immutability in JS: The Complete Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.taniarascia.com/javascript-modules-import-export/&#34;&gt;Understanding Modules, Import, and Export in JS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DOM&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://javascript.info/&#34;&gt;The Modern JS Tutorial: DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.digitalocean.com/community/books/understanding-the-dom-document-object-model-ebook&#34;&gt;Understanding the DOM (free ebook)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>How Web Apps Work: Browsers, HTML, and CSS</title>
      <link>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/</link>
      <pubDate>Mon, 09 Nov 2020 11:00:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Web development is a huge field with a vast array of concepts, terms, tools, and technologies.  For people just getting started in web dev, this landscape is often bewildering - it&#39;s unclear what most of these pieces are, much less how they fit together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This series provides an overview of fundamental web dev concepts and technologies, what these pieces are, why they&#39;re needed, and how they relate to each other&lt;/strong&gt;.  It&#39;s not a completely exhaustive reference to everything in web development, nor is it a &amp;quot;how to build apps&amp;quot; guide.  Instead, it&#39;s a map of the territory, &lt;strong&gt;intended to give you a sense of what the landscape looks like, and enough information that you can go research these terms and topics in more depth if needed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some of the descriptions will be more oriented towards modern client-side app development with JavaScript, but most of the topics are fundamental enough that they apply to server-centric applications as well.&lt;/p&gt;

&lt;p&gt;Other posts in this series cover additional topics, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/&#34;&gt;HTTP and Servers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/&#34;&gt;Client Development and Deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-javascript-dom/&#34;&gt;JavaScript and the DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-ajax-apis-data/&#34;&gt;AJAX, APIs, and Data Transfer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New terms will be marked in &lt;em&gt;italics&lt;/em&gt;.  I&#39;ll link references for some of them, but encourage you to search for definitions yourself.  Also, some of the descriptions will be simplified to avoid taking up too much space or dealing with edge cases.&lt;/p&gt;

&lt;p&gt;There&#39;s a comprehensive set of HTML and CSS tutorials at &lt;a href=&#34;https://www.internetingishard.com/html-and-css/&#34;&gt;&lt;strong&gt;Interneting is Hard: HTML and CSS&lt;/strong&gt;&lt;/a&gt;, with beautiful diagrams and great explanations of these terms and concepts.  (I&#39;ve borrowed a few of their excellent diagrams for this post.)&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;https://css-tricks.com/guides/&#34;&gt;&lt;strong&gt;CSS Tricks&lt;/strong&gt;&lt;/a&gt; has some amazing guides to specific aspects of CSS, like their guides for &lt;a href=&#34;https://css-tricks.com/snippets/css/a-guide-to-flexbox/&#34;&gt;Flexbox&lt;/a&gt; and &lt;a href=&#34;https://css-tricks.com/snippets/css/complete-guide-grid/&#34;&gt;CSS Grid&lt;/a&gt;, as well as numerous articles on other CSS and web dev topics.&lt;/p&gt;

&lt;p&gt;My &lt;a href=&#34;https://blog.isquaredsoftware.com/2019/05/presentation-js-for-java-devs/&#34;&gt;&lt;strong&gt;JavaScript for Java Developers slides&lt;/strong&gt;&lt;/a&gt; also cover much of this post&#39;s content as well.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#browsers&#34;&gt;Browsers&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#browser-rendering-behavior-variations&#34;&gt;Browser Rendering Behavior Variations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#browser-versions&#34;&gt;Browser Versions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#major-browsers&#34;&gt;Major Browsers&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#browser-notes&#34;&gt;Browser Notes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#html&#34;&gt;HTML&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#html-tags&#34;&gt;HTML Tags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#html-page-structure&#34;&gt;HTML Page Structure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#common-html-tags&#34;&gt;Common HTML Tags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#common-attributes&#34;&gt;Common Attributes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#forms&#34;&gt;Forms&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#css&#34;&gt;CSS&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#css-syntax&#34;&gt;CSS Syntax&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#css-selectors&#34;&gt;CSS Selectors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#css-styling-rules&#34;&gt;CSS Styling Rules&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#page-layout&#34;&gt;Page Layout&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#the-box-model&#34;&gt;The Box Model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#display-and-positioning&#34;&gt;Display and Positioning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#flexbox&#34;&gt;Flexbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#css-grid&#34;&gt;CSS Grid&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#responsive-screen-size-ui&#34;&gt;Responsive Screen Size UI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-resources&#34;&gt;Further Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;browsers&#34;&gt;Browsers&lt;/h2&gt;

&lt;p&gt;Any application can make requests using the HTTP protocol.  However, &lt;em&gt;web browsers&lt;/em&gt; are applications whose primary purpose is to request data using HTTP, format the content, and display it on screen.  That content is normally defined using the &lt;a href=&#34;#html&#34;&gt;&lt;em&gt;HTML&lt;/em&gt;&lt;/a&gt; format, and the appearance of the content is defined using &lt;a href=&#34;#css&#34;&gt;&lt;em&gt;CSS&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A browser&#39;s implementation can be divided into several areas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;em&gt;networking&lt;/em&gt; logic that is used to request data&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;rendering engine&lt;/em&gt; that parses fetched content, determines how it should be laid out on screen, processes the styling rules, and actually draws the pixels on screen&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;JavaScript engine&lt;/em&gt; that parses and executes JS code&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;browser chrome&lt;/em&gt; that defines the visible UI around the page content (buttons, menus, address bar, etc)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Different browser implementations may share and reuse implementation pieces, but use their own unique implementations for other sections.  For example, several browsers are built on top of the &amp;quot;Blink&amp;quot; rendering engine, like Chrome and Edge, but have very different UI implementations and user-visible features.&lt;/p&gt;

&lt;h3 id=&#34;browser-rendering-behavior-variations&#34;&gt;Browser Rendering Behavior Variations&lt;/h3&gt;

&lt;p&gt;Browsers all attempt to implement the same language specifications, but each browser ends up implementing those specifications differently.  Most of the time the behavior is the same, but browsers frequently have differences in behavior for the exact same features.  This has become less of a problem in recent years, as browser support for major specifications has become more consistent, but browser &amp;quot;quirks&amp;quot; in layout, appearance, and JS support are still a major pain point for web developers.&lt;/p&gt;

&lt;p&gt;Browsers can also always try adding new features themselves, but in order for features to be considered &amp;quot;standardized&amp;quot;, they typically need to be implemented by at least two different browsers and go through the appropriate web specification committees.&lt;/p&gt;

&lt;h3 id=&#34;browser-versions&#34;&gt;Browser Versions&lt;/h3&gt;

&lt;p&gt;Each time a browser ships a new version, that version has a fixed understanding of a certain subset of the HTML, CSS, and JS specifications.  Since that browser version may stay in wide use for many years, developers need to determine what set of browsers and versions they plan to support when developing a site or application.&lt;/p&gt;

&lt;p&gt;Browsers originally had infrequent releases of new versions, and each new version had many significant changes.  Today, most modern browsers release new versions frequently (every 6-8 weeks), and each new version only has a few meaningful changes.  These browsers are referred to as &lt;em&gt;evergreen browsers&lt;/em&gt;, because there&#39;s always a new version available and most users will automatically be upgraded to the latest version.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://caniuse.com/&#34;&gt;&amp;quot;Can I Use?&amp;quot; site&lt;/a&gt; is an incredibly useful resource that has a database of different HTML, CSS, and JS features, and lists which browser versions support each feature as well as how much worldwide market share those browsers have.  This is a valuable tool for deciding whether you can safely use a given feature in your site, based on your target audience.  For example, the &lt;a href=&#34;https://caniuse.com/css-sticky&#34;&gt;CSS &lt;code&gt;position: sticky&lt;/code&gt; layout feature&lt;/a&gt; currently has 95% support worldwide, but does not work in Internet Explorer.  So, if your target audience still includes IE11 users, you might not want to use that feature.&lt;/p&gt;

&lt;h3 id=&#34;major-browsers&#34;&gt;Major Browsers&lt;/h3&gt;

&lt;p&gt;The majority of browser market share belongs to a few major browsers.  By far the biggest one is Google Chrome.&lt;/p&gt;

&lt;p&gt;The market share of each browser has gone up and down over time.  Internet Explorer had a near-monopoly in the early 2000s until Firefox became popular.  Chrome took over from both of them, and Safari has become a major factor on mobile.  Browser market share also varies significantly in different countries.&lt;/p&gt;

&lt;p&gt;The browser market share as of October 2020 looks roughly like this.  Note that there are rather different usage percentages for desktop devices vs mobile devices:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Company&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Evergreen&lt;/th&gt;
&lt;th&gt;Rendering Engine&lt;/th&gt;
&lt;th&gt;Desktop %&lt;/th&gt;
&lt;th&gt;Mobile %&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;Google&lt;/td&gt;
&lt;td&gt;86&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Blink&lt;/td&gt;
&lt;td&gt;70%&lt;/td&gt;
&lt;td&gt;63%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;Apple&lt;/td&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;WebKit&lt;/td&gt;
&lt;td&gt;8%&lt;/td&gt;
&lt;td&gt;24%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;Mozilla&lt;/td&gt;
&lt;td&gt;82&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Gecko&lt;/td&gt;
&lt;td&gt;7%&lt;/td&gt;
&lt;td&gt;0.50%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Edge&lt;/td&gt;
&lt;td&gt;Microsoft&lt;/td&gt;
&lt;td&gt;86&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Blink&lt;/td&gt;
&lt;td&gt;6%&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Opera&lt;/td&gt;
&lt;td&gt;Opera&lt;/td&gt;
&lt;td&gt;72&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Blink&lt;/td&gt;
&lt;td&gt;2%&lt;/td&gt;
&lt;td&gt;2%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Samsung Internet&lt;/td&gt;
&lt;td&gt;Samsung&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Blink&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;td&gt;6%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Edge (legacy)&lt;/td&gt;
&lt;td&gt;Microsoft&lt;/td&gt;
&lt;td&gt;44&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;EdgeHTML&lt;/td&gt;
&lt;td&gt;1%&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Internet Explorer&lt;/td&gt;
&lt;td&gt;Microsoft&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Trident&lt;/td&gt;
&lt;td&gt;2%&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&#34;browser-notes&#34;&gt;Browser Notes&lt;/h4&gt;

&lt;p&gt;Some notes on the major browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chrome:

&lt;ul&gt;
&lt;li&gt;Built on an open-source core called &amp;quot;Chromium&amp;quot;, which is effectively Chrome minus all the actual Google account integration and branding&lt;/li&gt;
&lt;li&gt;The &amp;quot;Chrome&amp;quot; browser partly got its name because it tried to minimize the amount of &amp;quot;browser chrome&amp;quot; (the term for all the browser UI that surrounds the actual page content)&lt;/li&gt;
&lt;li&gt;Google has a tendency to announce new web features that only exist in Chrome and yet consider them &amp;quot;final&amp;quot; even if other browsers haven&#39;t added them yet&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Safari:

&lt;ul&gt;
&lt;li&gt;The only actual browser rendering engine allowed by Apple on iOS devices.  Any other browsers you see on iOS are actually the Safari core with a different UI skin and branding.&lt;/li&gt;
&lt;li&gt;Apple tends to be slow adding new features to Safari even after they&#39;ve been added to other browsers.  Apple has also refused to add certain features on the grounds that they might make act as privacy leaks in some way.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Firefox:

&lt;ul&gt;
&lt;li&gt;Open-source, and built by the Mozilla organization - it&#39;s the only major browser not built by one of the big tech companies&lt;/li&gt;
&lt;li&gt;Now that many browsers build on top of Chromium/Blink or Webkit, Firefox&#39;s &amp;quot;Gecko&amp;quot; engine is the main alternative rendering engine still in meaningful use.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Edge:

&lt;ul&gt;
&lt;li&gt;There&#39;s been two different variations of the MS Edge browser. The first was actually built entirely by Microsoft, using a cleaned-up and modernized version of the rendering engine previously used in Internet Explorer. Recently, Microsoft stopped developing their own rendering engine, labeled that version of Edge as &amp;quot;legacy&amp;quot;, and rebuilt Edge on top of Chromium with their own UI.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Internet Explorer:

&lt;ul&gt;
&lt;li&gt;IE was the default browser on Windows up until recently.  Many companies still have internal websites that only work correctly in IE, which keeps it as a small but persistent portion of the market&lt;/li&gt;
&lt;li&gt;IE has &amp;quot;stagnated&amp;quot; twice. IE6 came out in 2001 along with Windows XP, but Microsoft stopped developing it for several years until Firefox and Chrome began taking away market share.  Today, IE11 is considered an obsolete browser without many modern capabilities, and many companies are finally dropping support for running their sites in IE11.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;html&#34;&gt;HTML&lt;/h2&gt;

&lt;p&gt;Browsers request data from servers using the HTTP protocol.  The standard format that browsers read and use to display data is &lt;em&gt;HyperText Markup Language (HTML)&lt;/em&gt;.  HTML is a plain-text format that uses a hierarchy of nested &lt;em&gt;HTML tags&lt;/em&gt; to describe the content, layout, and formatting of a web page.&lt;/p&gt;

&lt;h3 id=&#34;html-tags&#34;&gt;HTML Tags&lt;/h3&gt;

&lt;p&gt;An HTML tag is a unique name that is written surrounded by angle brackets, like &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, or &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;.  Most tags also need to have a corresponding closing tag element, and may contain content inside.  For example, a paragraph tag may have text and images inside, and a list tag will have list item tags.&lt;/p&gt;

&lt;p&gt;Some tags are also self-closing, such as &lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;hr /&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Tags are not case-sensitive, but are usually written lower-case: &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, not &lt;code&gt;&amp;lt;IMG&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Tags may also have &lt;em&gt;attributes&lt;/em&gt;, written as &lt;code&gt;attributeName=&amp;quot;someValue&amp;quot;&lt;/code&gt;.  Some attributes don&#39;t need an actual value - the existence of the attribute name is all that&#39;s needed, such as &lt;code&gt;&amp;lt;input disabled&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The HTML spec defines dozens of different tags, each with a different purpose.  Browsers determine what should actually be displayed by parsing these tags.&lt;/p&gt;

&lt;h3 id=&#34;html-page-structure&#34;&gt;HTML Page Structure&lt;/h3&gt;

&lt;p&gt;A standard HTML page structure consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an outer &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tag that contains:

&lt;ul&gt;
&lt;li&gt;an optional &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag that may have metadata-related tags inside, as well as links to additional asset files that the browser should download&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag containing the actual content of the page&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A basic example would look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;My Website&amp;lt;/title&amp;gt;
    &amp;lt;link rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot; href=&amp;quot;styles.css&amp;quot;&amp;gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;logic.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Welcome to My Website&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;
      Here&#39;s some &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt; text, and an image:
    &amp;lt;/p&amp;gt;
    &amp;lt;img src=&amp;quot;party-parrot.gif&amp;quot; /&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;HTML tags are normally written with indented spacing for each level of nesting, but that&#39;s only needed for readability by people - browsers don&#39;t care about that.&lt;/p&gt;

&lt;p&gt;HTML pages may also start with a &lt;code&gt;&amp;lt;doctype&amp;gt;&lt;/code&gt; tag that declares the HTML version being used by the file, although that isn&#39;t necessary.&lt;/p&gt;

&lt;h3 id=&#34;common-html-tags&#34;&gt;Common HTML Tags&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Core tags

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;: The outer container of an HTML page&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;: the header section with metadata&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;: the main content of an HTML page&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; through &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;: headers of varying sizes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;: text paragraphs&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;: a generic block&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;: a generic inline piece of content&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;img src=&amp;quot;some-image.png&amp;quot;&amp;gt;&lt;/code&gt;: links to an image to be displayed&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;http://www.example.com&amp;quot;&amp;gt;&lt;/code&gt;: an anchor tag that may point to another page, or a specific location within this page. Clicking an anchor tells the browser to navigate to that URL.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Headers:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;: Page title, shown in the current tab / browser window&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt;: assorted metadata attributes describing a page&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;: link to assets such as stylesheets&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;: link to JavaScript files, or containing inline JS code&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Formatting

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;i&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;u&amp;gt;&lt;/code&gt;: bold, italic, underlined text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt;: represents a formatted quotation&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Lists

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;: list parents.  Unordered lists show bullet points for each list item, ordered lists show numbers.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;: list items inside of lists&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Tables

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt;: defines a table with rows columns&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt;: a single row in the table&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;thead&amp;gt;&lt;/code&gt;: the header area for the table&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;th&amp;gt;&lt;/code&gt;: header cells in a row in the header&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;tbody&amp;gt;&lt;/code&gt;: the body of the table&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;td&amp;gt;&lt;/code&gt;: a normal cell in a row in the body&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Forms

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;: a form area with inputs&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;: a user-editable input. Browsers have many types of inputs built in, most of which are used by passing a different &lt;code&gt;type&lt;/code&gt; attribute to &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;. Common inputs are:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;text&amp;quot;&lt;/code&gt;: a one-row textbox&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;checkbox&amp;quot;&lt;/code&gt;: a clickable true/false checkbox&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;radio&amp;quot;&lt;/code&gt;: a clickable button where only one value of a group can be selected at a time&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;file&amp;quot;&lt;/code&gt;: allows the user to select and upload a file from the local computer&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;: a dropdown for selecting a single value from a list&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;option&amp;gt;&lt;/code&gt;: a single selectable value in a dropdown&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;textarea&lt;/code&gt;&amp;gt; a multi-line textbox&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;: a descriptive label associated with an input&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some tags do basically the same thing as other tags, but are considered to be more &amp;quot;semantic&amp;quot;.  &lt;em&gt;Semantic markup&lt;/em&gt; is the idea that HTML tags should be meaningfully readable to both other developers and the browser itself.  For example, a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; is a generic block of content.  The HTML spec now has tags like &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;, which behave the same way display-wise, but are intended to be more meaningful in terms of what content they will contain.&lt;/p&gt;

&lt;h3 id=&#34;common-attributes&#34;&gt;Common Attributes&lt;/h3&gt;

&lt;p&gt;There are several common attributes that can be applied to any tag:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;id=&amp;quot;someValue&amp;quot;&lt;/code&gt;: gives a globally unique &amp;quot;ID&amp;quot; name to this element. There can be many IDs in a page, but each unique ID should only exist once in a page at a time&lt;/li&gt;
&lt;li&gt;&lt;code&gt;class=&amp;quot;first second third&amp;quot;&lt;/code&gt;: a space-separated list of &amp;quot;class names&amp;quot;, used to help identify elements for styling and searches&lt;/li&gt;
&lt;li&gt;&lt;code&gt;title=&amp;quot;Some description&amp;quot;&lt;/code&gt;: descriptive text, usually shown in a tooltip when hovering over the element&lt;/li&gt;
&lt;li&gt;&lt;code&gt;style=&amp;quot;color: red; background-color: blue;&amp;quot;&lt;/code&gt;: a list of &lt;em&gt;inline style&lt;/em&gt; rules to change the display of this element. Uses semi-colon-separated &lt;a href=&#34;#css&#34;&gt;CSS rules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;alt=&amp;quot;Some description&amp;quot;&lt;/code&gt;: descriptive text, typically supplied for images for use when the image can&#39;t be displayed, or read by a screen reader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other attributes only work for certain tags:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;img src=&amp;quot;some-image.jpg&amp;quot;&amp;gt;&lt;/code&gt;: the URL for the image to show&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;http://www.example.com&amp;quot;&amp;gt;&lt;/code&gt;: the URL for the link&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;input type=&amp;quot;checkbox&amp;quot;&amp;gt;&lt;/code&gt;: the type of input element to show&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;forms&#34;&gt;Forms&lt;/h3&gt;

&lt;p&gt;HTML forms allow users to enter values into the browser, such as typing in text or selecting items from a dropdown.  The browser maintains the current value of each input internally as the user interacts with the inputs.&lt;/p&gt;

&lt;p&gt;Input elements can be put anywhere, but should normally be put inside a &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; tag, which adds some extra behavior.  In particular, forms can be &lt;em&gt;submitted&lt;/em&gt; - the browser will automatically gather up the values of each input and send them via HTTP request to the server (normally an HTTP &lt;code&gt;POST&lt;/code&gt; request).&lt;/p&gt;

&lt;p&gt;A basic form might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;form action=&amp;quot;/create-user&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt; 
    &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;
            &amp;lt;label for=&amp;quot;name&amp;quot;&amp;gt;Name:&amp;lt;/label&amp;gt;
            &amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot; name=&amp;quot;user_name&amp;quot; /&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;
            &amp;lt;label for=&amp;quot;state&amp;quot;&amp;gt;State&amp;lt;/label&amp;gt;
            &amp;lt;select name=&amp;quot;state&amp;quot;&amp;gt;
              &amp;lt;option value=&amp;quot;ca&amp;quot;&amp;gt;California&amp;lt;/option&amp;gt;
              &amp;lt;option value=&amp;quot;oh&amp;quot;&amp;gt;Ohio&amp;lt;/option&amp;gt;
              &amp;lt;option value=&amp;quot;ny&amp;quot;&amp;gt;New York&amp;lt;/option&amp;gt;
            &amp;lt;/select&amp;gt;
        &amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;
            &amp;lt;label for=&amp;quot;msg&amp;quot;&amp;gt;Message:&amp;lt;/label&amp;gt;
            &amp;lt;textarea id=&amp;quot;msg&amp;quot; name=&amp;quot;user_message&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
    &amp;lt;button type=&amp;quot;submit&amp;quot;&amp;gt;Create User&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Side note: a &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; in a form defaults to &amp;quot;submit this form&amp;quot; when clicked.  If you want to do something else like handling logic in JavaScript (which is common in UI frameworks like React), you need to declare it as a &lt;code&gt;&amp;lt;button type=&amp;quot;button&amp;quot;&amp;gt;&lt;/code&gt; instead.&lt;/p&gt;

&lt;h2 id=&#34;css&#34;&gt;CSS&lt;/h2&gt;

&lt;p&gt;HTML describes a page&#39;s overall structure and layout, and browsers have a default basic appearance for each tag.  However, every page needs additional styling information added: colors, fonts, layout, and more.  This is done with &lt;em&gt;Cascading Style Sheets (CSS)&lt;/em&gt;, a declarative language that allows adding styling rules to ased on queries that match some set of HTML elements.&lt;/p&gt;

&lt;p&gt;CSS declarations can be added to an HTML page by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linking a separate CSS file in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of the document&lt;/li&gt;
&lt;li&gt;Adding a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag to the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; with CSS declarations inside&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alternately, styling rules can be written directly on an element in the HTML with the &lt;code&gt;style&lt;/code&gt; attribute, referred to as &lt;em&gt;inline styles&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id=&#34;css-syntax&#34;&gt;CSS Syntax&lt;/h3&gt;

&lt;p&gt;CSS syntax consists of two major pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;selectors&lt;/em&gt;, which are queries that define what elements will be matched&lt;/li&gt;
&lt;li&gt;&lt;em&gt;rules&lt;/em&gt;, which are the individual styling values that will be assigned to all matching elements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The basic syntax consists of a selector followed by a curly-brace block.  The block may contain one or more rules, where each rule looks like &lt;code&gt;property-name: value;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Multiple selectors may be declared in front of a rule block, and again any elements that match any of those selectors will be affected by the style rules.&lt;/p&gt;

&lt;p&gt;A basic CSS example might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;div.active {
  font-weight: bold;
  font-size: 24px;
  color: red;
  border: 1px solid blue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;CSS only allows comments using the same multi-line comment syntax as many other languages:
&lt;code&gt;/* comment here */&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&#34;css-selectors&#34;&gt;CSS Selectors&lt;/h3&gt;

&lt;p&gt;CSS selectors can contain many different pieces that uniquely identify some set of elements.  Some of the most common matching pieces are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Specific HTML tag types: by name of the tag, without angle brackets ( &lt;code&gt;h1&lt;/code&gt; )&lt;/li&gt;
&lt;li&gt;Tags with a given classname: by a &lt;code&gt;.&lt;/code&gt; in front of the classname ( &lt;code&gt;.myClassname&lt;/code&gt; )&lt;/li&gt;
&lt;li&gt;Tags with a given ID: by a &lt;code&gt;#&lt;/code&gt; in front of the ID value ( &lt;code&gt;#myId&lt;/code&gt; )&lt;/li&gt;
&lt;li&gt;Nesting: adding spaces between selector query pieces ( &lt;code&gt;main form.signup input#firstName&lt;/code&gt; )&lt;/li&gt;
&lt;li&gt;Immediate children: putting a &lt;code&gt;&amp;gt;&lt;/code&gt; between parent and child ( &lt;code&gt;ul.items &amp;gt; li&lt;/code&gt; )&lt;/li&gt;
&lt;li&gt;The &amp;quot;universal selector&amp;quot; uses a &lt;code&gt;*&lt;/code&gt; to match everything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are also &lt;em&gt;pseudo-class&lt;/em&gt; selectors, which apply an additional modifier to the selector matching, and are usually based on some aspect of the element&#39;s behavior.  For example, the &lt;code&gt;:hover&lt;/code&gt; pseudo-class only matches an element where the mouse is currently hovering, and the &lt;code&gt;:disabled&lt;/code&gt; pseudo-class only matches an element that is currently marked as disabled.  The  &lt;code&gt;:nth-child&lt;/code&gt; pseudo-class is commonly used for striping the background color of alternating table rows based on even/odd row numbers, and there&#39;s dozens of others as well.&lt;/p&gt;

&lt;p&gt;An element&#39;s final style is made up of all of the combined rules that apply to it.  Children inherit most properties from their parents.  A rule &lt;code&gt;html {font-family: Courier New;}&lt;/code&gt; would set that font as a default for the whole document, but a nested child could have its own &lt;code&gt;font-family&lt;/code&gt; value that would override the value it inherited.&lt;/p&gt;

&lt;p&gt;There are rules for &lt;em&gt;selector specificity&lt;/em&gt;, which define which values take effect when there are multiple competing rules+properties that apply to a given element. More specific rules will override less specific rules.  Inline styles have much higher precedence than styles defined separately.  Adding a &lt;code&gt;!important&lt;/code&gt; at the end of a rule raises its specificity by a large amount, like &lt;code&gt;color: red !important;&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&#34;css-styling-rules&#34;&gt;CSS Styling Rules&lt;/h3&gt;

&lt;p&gt;There are hundreds of CSS properties that can be modified.  They range from very simple (changing the text color) to highly complex (creating multi-point color gradients, defining polygon clip masks).  Multi-word CSS property names are hyphenated (&lt;code&gt;background-color&lt;/code&gt;, &lt;code&gt;font-weight&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Many CSS properties can be grouped by concept, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Element backgrounds: &lt;code&gt;background-color&lt;/code&gt;, &lt;code&gt;background-image&lt;/code&gt;, &lt;code&gt;background-repeat&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Borders: &lt;code&gt;border-left&lt;/code&gt;, &lt;code&gt;border-color&lt;/code&gt;, &lt;code&gt;border-width&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Fonts: &lt;code&gt;font-family&lt;/code&gt;, &lt;code&gt;font-weight&lt;/code&gt;, &lt;code&gt;font-size&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Spacing: &lt;code&gt;margin-top&lt;/code&gt;, &lt;code&gt;padding-bottom&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Sizing: &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;width&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Layout: &lt;code&gt;display&lt;/code&gt;, &lt;code&gt;position&lt;/code&gt;, &lt;code&gt;overflow&lt;/code&gt;, &lt;code&gt;z-index&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Different properties can accept different kinds of values, and values can often be given in different units.  For example, &lt;code&gt;font-size&lt;/code&gt; accepts values using &amp;quot;length units&amp;quot;, which can be in pixels (&lt;code&gt;px&lt;/code&gt;), size relative to parent ( &lt;code&gt;em&lt;/code&gt;), size relative to the &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; element ( &lt;code&gt;rem&lt;/code&gt; ), actual display sizes ( &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;mm&lt;/code&gt;, &lt;code&gt;cm&lt;/code&gt; ), and more.  Layout widths and heights are often given in percentages ( &lt;code&gt;%&lt;/code&gt; ) or pixels.&lt;/p&gt;

&lt;p&gt;CSS examples:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;div { /* will apply to all div tags */
    color: red; /* text color */
}

div span { /* only spans nested in divs */
    color : blue; /* overrides red color */
    font-weight: bold;
}

#some-id { /* only applies to tag with this ID */
    font-size: 24px;
}

.someClassname { /* any tag with this classname */
    border: 1px solid green;
}

p.first.second { /* only paragraphs with both classnames */
    margin: 5px;
}

div.classA , span.classB { /* applies to either */
    min-width: 50%;
    max-height: 300px;
}

div &amp;gt; p { /* only paras as direct children of divs */
    display : none; /* hide entirely */
}

div.myClass:hover { /* only applies on mouse hover */
    border: 1px dotted orange;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;page-layout&#34;&gt;Page Layout&lt;/h2&gt;

&lt;p&gt;There are many factors that affect how elements are positioned in a page, and what their size and shape is compared to other elements.  HTML has default layout before defined for each element type, but CSS properties can completely change an element&#39;s position and layout behavior.&lt;/p&gt;

&lt;h3 id=&#34;the-box-model&#34;&gt;The Box Model&lt;/h3&gt;

&lt;p&gt;The default layout behavior is called the &lt;em&gt;box model&lt;/em&gt;.  Every HTML element is treated as a rectangular box, and falls into one of two categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;block boxes&lt;/em&gt; stack downwards vertically&lt;/li&gt;
&lt;li&gt;&lt;em&gt;inline boxes&lt;/em&gt; stack sideways horizontally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tags are blocks. Adding &lt;code&gt;&amp;lt;div /&amp;gt;&amp;lt;div /&amp;gt;&amp;lt;div /&amp;gt;&lt;/code&gt; will produce three elements in a column going down the page.  On the other hand, &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; tags are inline.  Adding &lt;code&gt;&amp;lt;span /&amp;gt;&amp;lt;span /&amp;gt;&amp;lt;span /&amp;gt;&lt;/code&gt; will lay out all three spans side-by-side.&lt;/p&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2020-11-how-web-apps-work-html-css-dom/turning-inline-into-block-boxes-772f4c.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2020-11-how-web-apps-work-html-css-dom/turning-inline-into-block-boxes-772f4c.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;An element&#39;s default behavior can be changed using the various options for the &lt;code&gt;display&lt;/code&gt; and &lt;code&gt;position&lt;/code&gt; properties.  For example, adding &lt;code&gt;display: inline;&lt;/code&gt; to a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag will make it behave the same as a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; normally would.&lt;/p&gt;

&lt;p&gt;The size of a given element is made up of several pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The actual content&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Padding&lt;/em&gt;: extra spacing that is still &amp;quot;inside&amp;quot; the element&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Border&lt;/em&gt; : extra lines around / &amp;quot;outside&amp;quot; the element&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Margin&lt;/em&gt;: extra spacing that is considered &amp;quot;outside&amp;quot; the element&lt;/li&gt;
&lt;/ul&gt;


&lt;figure &gt;
    &lt;a href=&#34;https://blog.isquaredsoftware.com/images/2020-11-how-web-apps-work-html-css-dom/css-box-model-73a525.png&#34;&gt;
        &lt;img src=&#34;https://blog.isquaredsoftware.com/images/2020-11-how-web-apps-work-html-css-dom/css-box-model-73a525.png&#34; /&gt;
    &lt;/a&gt;
    
&lt;/figure&gt;


&lt;p&gt;The &amp;quot;padding and border outside&amp;quot; sizing behavior can sometimes feel unexpected, The behavior can be altered using &lt;code&gt;box-sizing: border-box;&lt;/code&gt;, which alters the sizing calculations so that the &amp;quot;total width&amp;quot; of an element includes all of its border and padding as well.&lt;/p&gt;

&lt;h3 id=&#34;display-and-positioning&#34;&gt;Display and Positioning&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;display&lt;/code&gt; and &lt;code&gt;position&lt;/code&gt; properties can be used to alter how an element&#39;s layout behavior works.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;display: block;&lt;/code&gt; and &lt;code&gt;display: inline;&lt;/code&gt; values force an element to one of the standard layout behaviors. There are also specialized layout behaviors, like &lt;a href=&#34;#flexbox&#34;&gt;Flexbox&lt;/a&gt; and &lt;a href=&#34;#css-grid&#34;&gt;CSS Grid&lt;/a&gt; (described below).&lt;/p&gt;

&lt;p&gt;Elements can be removed from the page completely using &lt;code&gt;display: none;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;position&lt;/code&gt; property takes several values, some of which work in combination with the &lt;code&gt;top/bottom/left/right&lt;/code&gt; numeric properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;position: static&lt;/code&gt;: the default&lt;/li&gt;
&lt;li&gt;&lt;code&gt;position: relative&lt;/code&gt;: offset the location by some amount&lt;/li&gt;
&lt;li&gt;&lt;code&gt;position: fixed&lt;/code&gt;: stays in a single location on screen, even as the document moves around&lt;/li&gt;
&lt;li&gt;&lt;code&gt;position: absolute&lt;/code&gt;: stays in a single location within the document, without following normal layout flow&lt;/li&gt;
&lt;li&gt;&lt;code&gt;position: sticky&lt;/code&gt;: a newer option that keeps items in place for a while until the page scrolls well past them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any value other than &lt;code&gt;static&lt;/code&gt; creates a new &lt;em&gt;stacking context&lt;/em&gt;. Loosely put, any children will be positioned with their &lt;code&gt;top&lt;/code&gt; and &lt;code&gt;left&lt;/code&gt; values relative to where this element is located.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;z-index&lt;/code&gt; property affects how elements &amp;quot;stack&amp;quot; on top of each other when they overlap.  (Frankly, the &lt;code&gt;z-index&lt;/code&gt; property confuses just about everyone, so I&#39;m not even going to explain more than that here because I&#39;ll probably get it wrong, but please research it further.)&lt;/p&gt;

&lt;h3 id=&#34;flexbox&#34;&gt;Flexbox&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Flexbox&lt;/em&gt; is a CSS layout algorithm that allows aligning items into rows or columns, with rules for aligning items and wrapping them as they overflow.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;flex parent&lt;/em&gt; is defined by adding a &lt;code&gt;display: flex&lt;/code&gt; rule to an element.  All of the immediate children are then laid out automatically as &lt;em&gt;flex items&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Key properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;flex-direction&lt;/code&gt;: the primary layout direction for the flexbox parent (row, column)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;justify-content&lt;/code&gt;: how items are aligned in that direction (start, end, separated)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;align-items&lt;/code&gt;: how items are aligned in the cross direction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Centering items both vertically and horizontally had been an exceptionally difficult task on the web for many years, but Flexbox allows centering things fairly easily, such as &lt;code&gt;display: flex; justify-content: center; align-items: center;&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&#34;css-grid&#34;&gt;CSS Grid&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;CSS Grid&lt;/em&gt; is a newer CSS layout algorithm designed for 2D layouts with various numbers of rows and columns.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;grid container&lt;/em&gt; is defined by adding a &lt;code&gt;display: grid&lt;/code&gt; rule to an element.  All of the immediate children are then laid out automatically as &lt;em&gt;grid items&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Grid syntax is extensive, and allows defining sets of columns and rows with varying repeated patterns.&lt;/p&gt;

&lt;h3 id=&#34;responsive-screen-size-ui&#34;&gt;Responsive Screen Size UI&lt;/h3&gt;

&lt;p&gt;Users may view a site using a wide variety of devices with varying screen sizes: desktops such as 1920x1080, tablets such as 768x1024, or phones such as 375x812.&lt;/p&gt;

&lt;p&gt;Designers and devs frequently need to create layouts that look good at many different screen sizes, referred to as &lt;em&gt;responsive design&lt;/em&gt;.  Rather than make completely different sites, they may add CSS rules that only apply in certain cases, such as when the viewing device screen is in a specific size range.  This is normally done using &lt;em&gt;media queries&lt;/em&gt;, which are CSS conditions that only apply the selectors and rules inside if the condition matches.  The CSS rules typically choose certain screen sizes as &lt;em&gt;breakpoints&lt;/em&gt; so that the layout changes if your device is larger or smaller than that size.  An example media query and breakpoint setup might look like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {
  .notice {
    color: red;
  }
}

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {
  .notice {
    color: green;
  }
}

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {
  .notice {
    color: blue;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;further-resources&#34;&gt;Further Resources&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Browsers&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.html5rocks.com/en/tutorials/internals/howbrowserswork/&#34;&gt;How Browsers Work: Behind the scenes of modern web browsers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/&#34;&gt;Code Cartoons: The whole web at maximum FPS (rendering engine painting)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/&#34;&gt;Code Cartoons: Inside a super fast CSS engine (styling rules and layout)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developers.google.com/web/updates/2012/04/Round-up-of-Web-Browser-Internals-Resources&#34;&gt;Roundup of Web Browser Internals Resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://caniuse.com/&#34;&gt;&amp;quot;Can I Use?&amp;quot; browser feature availability database&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HTML&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.internetingishard.com/html-and-css/&#34;&gt;Interneting is Hard: HTML and CSS Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML&#34;&gt;MDN: Introduction to HTML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Learn/HTML/Cheatsheet&#34;&gt;MDN: HTML Cheatsheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSS&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps&#34;&gt;MDN: CSS introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://css-tricks.com/how-css-selectors-work/&#34;&gt;CSS Tricks: How CSS Selectors Work&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://apps.workflower.fi/vocabs/css/en&#34;&gt;CSS Vocabulary: interactive CSS terms visual explainer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://alistapart.com/article/css-positioning-101/&#34;&gt;CSS Positioning 101&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://css-tricks.com/snippets/css/a-guide-to-flexbox/&#34;&gt;CSS Tricks: Complete Guide to Flexbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://css-tricks.com/snippets/css/complete-guide-grid/&#34;&gt;CSS Tricks: Complete Guide to Grid&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>How Web Apps Work: Client Development and Deployment</title>
      <link>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/</link>
      <pubDate>Fri, 06 Nov 2020 10:00:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Web development is a huge field with a vast array of concepts, terms, tools, and technologies.  For people just getting started in web dev, this landscape is often bewildering - it&#39;s unclear what most of these pieces are, much less how they fit together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This series provides an overview of fundamental web dev concepts and technologies, what these pieces are, why they&#39;re needed, and how they relate to each other&lt;/strong&gt;.  It&#39;s not a completely exhaustive reference to everything in web development, nor is it a &amp;quot;how to build apps&amp;quot; guide.  Instead, it&#39;s a map of the territory, &lt;strong&gt;intended to give you a sense of what the landscape looks like, and enough information that you can go research these terms and topics in more depth if needed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some of the descriptions will be more oriented towards modern client-side app development with JavaScript, but most of the topics are fundamental enough that they apply to server-centric applications as well.&lt;/p&gt;

&lt;p&gt;Other posts in this series cover additional topics, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/&#34;&gt;HTTP and Servers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/&#34;&gt;Browsers, HTML, and CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-javascript-dom/&#34;&gt;JavaScript and the DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-ajax-apis-data/&#34;&gt;AJAX, APIs, and Data Transfer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New terms will be marked in &lt;em&gt;italics&lt;/em&gt;.  I&#39;ll link references for some of them, but encourage you to search for definitions yourself.  Also, some of the descriptions will be simplified to avoid taking up too much space or dealing with edge cases.&lt;/p&gt;

&lt;p&gt;My &lt;a href=&#34;https://blog.isquaredsoftware.com/2019/05/presentation-js-for-java-devs/&#34;&gt;&lt;strong&gt;JavaScript for Java Developers slides&lt;/strong&gt;&lt;/a&gt; also cover much of this post&#39;s content as well.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#javascript-development-and-build-processes&#34;&gt;JavaScript Development and Build Processes&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#javascript-module-formats&#34;&gt;JavaScript Module Formats&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#legacy-module-formats&#34;&gt;Legacy Module Formats&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#commonjs-modules&#34;&gt;CommonJS Modules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#universal-module-definition&#34;&gt;Universal Module Definition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#es-modules&#34;&gt;ES Modules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#compiling&#34;&gt;Compiling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#bundling&#34;&gt;Bundling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#source-maps&#34;&gt;Source Maps&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#development-environments-and-tools&#34;&gt;Development Environments and Tools&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#nodejs&#34;&gt;Node.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#npm&#34;&gt;NPM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#node-build-tools&#34;&gt;Node Build Tools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#dev-servers&#34;&gt;Dev Servers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#hot-module-reloading&#34;&gt;Hot Module Reloading&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#deployment&#34;&gt;Deployment&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#serving-build-output&#34;&gt;Serving Build Output&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#polyfills&#34;&gt;Polyfills&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#code-splitting&#34;&gt;Code Splitting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-resources&#34;&gt;Further Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;javascript-development-and-build-processes&#34;&gt;JavaScript Development and Build Processes&lt;/h2&gt;

&lt;p&gt;It&#39;s important to understand the evolution of JavaScript&#39;s design and usage over time to understand why and how it gets used today.&lt;/p&gt;

&lt;p&gt;This quote sums things up well:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The by-design purpose of JavaScript was to make the monkey dance when you moused over it&lt;/strong&gt;. Scripts were often a single line. We considered ten line scripts to be pretty normal, hundred line scripts to be huge, and thousand line scripts were unheard of. The language was absolutely not designed for programming in the large, and our implementation decisions, performance targets, and so on, were based on that assumption.&lt;br /&gt;
- Eric Lippert, former IE/JS developer at Microsoft&lt;br /&gt;
  &lt;a href=&#34;http://programmers.stackexchange.com/a/221658/214387&#34;&gt;http://programmers.stackexchange.com/a/221658/214387&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Today, applications routinely consist of hundreds of thousands of lines of JavaScript.  This introduces a completely different set of constraints on how developers write, build, and deliver client-side applications.  Those constraints result in a very different development approach than the early days.  Instead of writing a few lines of JS and inlining them into an HTML page, modern web clients use complex build toolchains that are directly equivalent to compilers for languages like C++ or Java.&lt;/p&gt;

&lt;h3 id=&#34;javascript-module-formats&#34;&gt;JavaScript Module Formats&lt;/h3&gt;

&lt;p&gt;Almost all languages have built-in syntax for declaring encapsulated &amp;quot;modules&amp;quot; or &amp;quot;packages&amp;quot;.  For example, a Java file might declare it is part of &lt;code&gt;package com.my.project&lt;/code&gt;, and then declare a dependency on another package with &lt;code&gt;import some.other.project.SomeClass;&lt;/code&gt;.  C#, Python, Go, and Swift all have their own package definition and import/export syntax.&lt;/p&gt;

&lt;p&gt;JavaScript is not one of those languages.&lt;/p&gt;

&lt;p&gt;Unlike all these other languages, JavaScript originally had no built-in module format syntax.  For many years, JS code was written as inline &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags directly in HTML, or as small &lt;code&gt;.js&lt;/code&gt; files with a few shared global variables.&lt;/p&gt;

&lt;p&gt;As developers began writing larger application codebases, the community eventually began inventing their own module formats to help provide structure and encapsulation.  Each of these formats was invented to solve differing use cases.&lt;/p&gt;

&lt;p&gt;(&lt;strong&gt;Note&lt;/strong&gt;: code snippets in this section are purely to illustrate the syntax differences between the various formats - the actual code is not intended to run or do anything useful.)&lt;/p&gt;

&lt;h4 id=&#34;legacy-module-formats&#34;&gt;Legacy Module Formats&lt;/h4&gt;

&lt;p&gt;Adding numerous script tags to a page has several issues. It can be very hard to determine the dependencies between different script files and load them in the right order.  Also, since all top-level variables occupy the same global namespace, it&#39;s really easy to accidentally have variables with the same name overriding each other:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;&amp;lt;script src=&amp;quot;jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&amp;quot;jquery.someplugin.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&amp;quot;./components/dropdown.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&amp;quot;./components/modal.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&amp;quot;./application.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;

// dropdown.js
var delay = 2000; // in ms

// modal.js
var delay = 4000; // in ms

// application.js
// Oops - is it 2000 or 4000?
console.log(delay)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Immediately Invoked Function Expressions&lt;/em&gt; (IIFEs) are a pattern that rely on JS variables being scoped to the nearest function.  An IIFE involves defining a new function and then immediately calling it to get a result.  This provides encapsulation, and was used as the basis of the &amp;quot;revealing module&amp;quot; pattern, where an IIFE returns an object that defines its public API (equivalent to a factory function or a class constructor):&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// dropdown.js
(function(){
    var delay = 2000; // in ms
    APP.dropdown.delay = delay;
}());

// modal.js
const modalAPI = (function(){
    // No name clash - encapsulated in the IIFE
    var delay = 4000; // in ms
    APP.modal.delay = delay;

    $(&amp;quot;#myModal&amp;quot;).show();

    function hideModal() {
      $(&amp;quot;#myModal&amp;quot;).hide()
    }

    // return a &amp;quot;public API&amp;quot; for the modal by exposing methods
    return {
      hideModal : hideModal
    }
}());
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;em&gt;Asynchronous Module Definition&lt;/em&gt; format (AMD) was designed specifically to be used by browsers.  A specialized AMD loader library first creates a global &lt;code&gt;define&lt;/code&gt; function.  AMD modules then call &lt;code&gt;define()&lt;/code&gt; and pass in an array of module names they depend on, and a function that acts as the body of the module.  The module body function receives all its requested dependencies as arguments, and may return any single value to act as its &amp;quot;export&amp;quot;.  The loader library then checks to see if all of the requested dependencies have been registered and loaded.  If not, it recursively downloads other dependencies waterfall-style, and works its way back up the dependency chain to initialize each module function with its dependencies.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// moduleA.js
// Loader library adds a global `define()` function
define([&amp;quot;jquery&amp;quot;, &amp;quot;myOtherModule&amp;quot;],
function($, myOtherModule) {
    // Body of the function is the module definition
    const a = 42;
    const b = 123;

    function someFunction() { }

    // Return value is the &amp;quot;exports&amp;quot; of the module
    // Can do &amp;quot;named exports&amp;quot; by returning object with many values
    return {a : a, publicName : b, someFunction : someFunction}
});

// moduleB.js
define([&amp;quot;backbone&amp;quot;],
function(Backbone) {
    const MyModel = Backbone.Model.extend({});

    // Can do a &amp;quot;default&amp;quot; export by just returning one thing
    // instead of an object with multiple things inside
    return MyModel;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;IIFEs and AMD modules are no longer actively being used for new development, but code using those patterns is still out there.&lt;/p&gt;

&lt;h4 id=&#34;commonjs-modules&#34;&gt;CommonJS Modules&lt;/h4&gt;

&lt;p&gt;The CommonJS module format was developed specifically for use with the Node.js runtime (a JS interpreter running outside the browser).  Since Node has access to the filesystem, the CommonJS format was designed to load modules from disk synchronously as soon as they are imported.&lt;/p&gt;

&lt;p&gt;The Node.js interpreter defines a global &lt;code&gt;require&lt;/code&gt; function that accepts either relative paths, absolute paths, or library names.  Node then follows a complex lookup formula to find a file matching the requested path/name, and if found, immediately reads and loads the requested file.&lt;/p&gt;

&lt;p&gt;CommonJS modules do not have any outer wrapping function.  The interpreter also defines a global &lt;code&gt;module.exports&lt;/code&gt; variable, and the module defines its exported values by assigning to that variable.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// moduleA.js
// Node runtime system adds `require()` function and infrastructure
const $ = require(&amp;quot;jquery&amp;quot;);
const myOtherModule = require(&amp;quot;myOtherModule&amp;quot;);

// The entire file is the module definition
const a = 42;
const b = 123;

function someFunction() { }

// Node runtime adds a `module.exports` keyword to define exports
// Can do &amp;quot;named exports&amp;quot; by assigning an object with many values
module.exports = {  
    a : a, 
    publicName : b, 
    someFunction : someFunction 
}


// moduleB.js
const Backbone = require(&amp;quot;backbone&amp;quot;);
const MyModel = Backbone.Model.extend({});

// Can do a &amp;quot;default&amp;quot; export by just assigning
// one value to `module.exports`
module.exports = MyModel;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;CommonJS modules allow dynamically importing other modules at any time, and imports can be done conditionally.&lt;/p&gt;

&lt;p&gt;The flip side is that CommonJS modules cannot be used as-is in a browser - some kind of adapter or repackaging is needed.&lt;/p&gt;

&lt;h4 id=&#34;universal-module-definition&#34;&gt;Universal Module Definition&lt;/h4&gt;

&lt;p&gt;Some libraries need to be able to be used in multiple environments with the same build artifact: a plain global &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in a browser, an AMD module in a browser, or a CommonJS file under Node.  The community invented a bizarre-looking hack that allowed a module to work correctly in all three environments by feature-detecting capabilities, which was dubbed the &lt;em&gt;Universal Module Definition&lt;/em&gt; (UMD) format.  Today this is still semi-commonly used as a build output target for some libraries.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// File log.js
(function (global, factory) {
    if (typeof define === &amp;quot;function&amp;quot; &amp;amp;&amp;amp; define.amd) {
      define([&amp;quot;exports&amp;quot;], factory);
    } else if (typeof exports !== &amp;quot;undefined&amp;quot;) {
      factory(exports);
    } else {
      var mod = {
        exports: {}
      };
      factory(mod.exports);
      global.log = mod.exports;
    }
})(this, function (exports) {
  &amp;quot;use strict&amp;quot;;
  
  function log() {
    console.log(&amp;quot;Example of UMD module system&amp;quot;);
  }
  // expose log to other modules
  exports.log = log;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&#34;es-modules&#34;&gt;ES Modules&lt;/h4&gt;

&lt;p&gt;The ES2015 language spec finally added an official module syntax to the JS language, which is now referred to as &lt;em&gt;ES Modules&lt;/em&gt; or &amp;quot;ESM&amp;quot;.  It provides syntax for defining both &lt;em&gt;named&lt;/em&gt; and &lt;em&gt;default&lt;/em&gt; imports and exports.  However, due to the differences between browsers and Node.js, the specification did not define how modules would actually be loaded by an interpreter, or what the import strings would refer to, and instead left it up to the differing environments to figure out how to load modules appropriately.  Modern browsers have all implemented loading ES Modules based on URLs as the import strings.  Node has had significantly more trouble determining a path forward, due to its reliance on CommonJS modules as the default format.  As of Node 15, Node has some support for loading ES Modules, but there are still difficulties determining how CommonJS and ES Module files should interop with each other.&lt;/p&gt;

&lt;p&gt;ES Modules were designed to be statically analyzable.  The downside is that you cannot do dynamic or conditional imports - all imports and exports must be at the top level of the file.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;// moduleA.js
// ES6 language spec defines import/export keywords
import $ from &amp;quot;jquery&amp;quot;;
// Can do &amp;quot;default&amp;quot; imports - no curly braces around the variable name
import myOtherModule from &amp;quot;myOtherModule&amp;quot;;

// Define &amp;quot;named exports&amp;quot; by adding `export` in front of a variable
export const a = 42;
export const b = 123;
export {b as publicName};

export function someFunction() { }


// moduleB.js
// Can do &amp;quot;named imports&amp;quot; from other modules
import {Model} from &amp;quot;backbone&amp;quot;;
const MyModel = Model.extend({});

// Can do a &amp;quot;default&amp;quot; export with the `export default` keyword
export default MyModel;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;compiling&#34;&gt;Compiling&lt;/h3&gt;

&lt;p&gt;The JS language spec has added lots of additional syntax over the years.  The ES2015 spec in particular effectively doubled the amount of syntax in the language.&lt;/p&gt;

&lt;p&gt;Each time a browser ships a new version, that version has a fixed understanding of a certain subset of the JS language.  Since that browser version may stay in wide use for many years, developers need to ship code using only syntax that is supported by the set of browser versions they intend to support.  However, developers &lt;em&gt;also&lt;/em&gt; want to be able to write and develop code using the latest and greatest syntax.&lt;/p&gt;

&lt;p&gt;This means that developers need to compile the original &amp;quot;current&amp;quot; JS source code they&#39;ve written into an equivalent version that only uses older syntax.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://babeljs.io&#34;&gt;Babel JS compiler&lt;/a&gt; is the standard tool used to cross-compile JS code into a different variation of JS.  It has a wide array of plugins that support compiling specific pieces of newer JS language syntax into their older equivalent forms.&lt;/p&gt;

&lt;p&gt;As an example, this ES2015-compatible snippet uses ES Module syntax, arrow functions,  the &lt;code&gt;const/let&lt;/code&gt; variable declaration keywords, and the shorthand object declaration syntax:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;export const myFunc = () =&amp;gt; {
  let longVariableName = 1;
  return {longVariableName};
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When compiled by Babel with the ES2015 plugin enabled and targeting the CommonJS module format, it becomes:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;&amp;quot;use strict&amp;quot;;

Object.defineProperty(exports, &amp;quot;__esModule&amp;quot;, {
  value: true
});
exports.myFunc = void 0;

var myFunc = function myFunc() {
  var longVariableName = 1;
  return {
    longVariableName: longVariableName
  };
};

exports.myFunc = myFunc;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In addition, there are many &amp;quot;compile-to-JS&amp;quot; languages in use in the industry.  Some are obscure niche languages, some were popular for a few years and have since died out (CoffeeScript).  The most commonly used compile-to-JS language at this point is &lt;a href=&#34;https://www.typescriptlang.org/&#34;&gt;TypeScript&lt;/a&gt;, which is a statically-typed superset of JS created by Microsoft.  The TypeScript compiler itself strips out type annotations at compile time and outputs plain JS.  Similar to Babel, it can also compile newer syntax into varying older language versions.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-ts&#34;&gt;// Input: TypeScript syntax is JS with type annotations
const add2 = (x: number, y: number) =&amp;gt; {
  return x + y;
};

// Output: plain JS, no type annotations
const add2 = (x, y) =&amp;gt; {
  return x + y;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;bundling&#34;&gt;Bundling&lt;/h3&gt;

&lt;p&gt;There are multiple reasons why the original JS source cannot be delivered as-is to the browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code written in CommonJS format cannot be loaded by browsers&lt;/li&gt;
&lt;li&gt;Code written in ES Module format can be, but requires careful work to have all the files and path URLs line up correctly&lt;/li&gt;
&lt;li&gt;Target browsers used by consumers likely don&#39;t support all modern syntax&lt;/li&gt;
&lt;li&gt;Codebases may consist of thousands of separate JS files, and downloading each file separately would take too long to load&lt;/li&gt;
&lt;li&gt;Original source contains comments, whitespace, and longer variable names, and developers need to minimize the number of bytes sent to the browser to let pages load faster&lt;/li&gt;
&lt;li&gt;Languages like TypeScript are not supported by JS interpreters - the original source has to be compiled to plain JS syntax&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of this, JS code is also &lt;em&gt;bundled&lt;/em&gt; to prepare it for use in a browser.  This has to happen in both a development environment, and production.&lt;/p&gt;

&lt;p&gt;The bundling process traces the tree of imports and dependencies starting from a set of &lt;em&gt;entry point&lt;/em&gt; files (such as &lt;code&gt;src/index.js&lt;/code&gt;).  Any imported file is then added to the list of files to be processed.  The bundler resolves all requested imports, determines the necessary loading order, and outputs the module sources wrapped in some scaffolding that initializes the application when the bundle file is loaded.&lt;/p&gt;

&lt;p&gt;Bundling tools also typically support multiple additional processing steps during the bundling process.  In particular, bundlers will usually be configured to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;run a compiler like Babel or TypeScript on all JS/TS source files&lt;/li&gt;
&lt;li&gt;If using TS, do typechecks with the TS compiler to verify the code actually compiles&lt;/li&gt;
&lt;li&gt;Enable importing and processing additional assets like CSS and images&lt;/li&gt;
&lt;li&gt;Optimize the size of the output to make it as small as possibly, by &lt;em&gt;minifying&lt;/em&gt; it (also known as &lt;em&gt;uglifying&lt;/em&gt;).&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Minifying JS source involves shrinking the code as much as possible, by stripping out whitespace and comments, replacing long variable names with shorter names, and using the shortest possible versions of syntax.  Finally, minifiers can detect dead code and remove it, and JS code is often written with flags like &lt;code&gt;if (process.env.NODE_ENV !== &#39;production&#39;)&lt;/code&gt; to add development-only checks that will be removed in a production build.&lt;/p&gt;

&lt;p&gt;The same Babel-compiled output above looks like this when minified:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;&amp;quot;use strict&amp;quot;;Object.defineProperty(exports,&amp;quot;__esModule&amp;quot;,{value:!0}),exports.myFunc=void 0;var myFunc=function(){return{longVariableName:1}};exports.myFunc=myFunc;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href=&#34;https://webpack.js.org/&#34;&gt;Webpack&lt;/a&gt; is the most widely used JS bundler.  Other tools such as Parcel, Snowpack, and ESBuild fulfill the same roles, but with different goals and constraints.&lt;/p&gt;

&lt;h3 id=&#34;source-maps&#34;&gt;Source Maps&lt;/h3&gt;

&lt;p&gt;Because of these transformations, the code loaded by a browser has been mangled into a completely unrecognizable form that makes it impossible to actually debug as-is.  To solve this, development tools also write out &lt;em&gt;source maps&lt;/em&gt;, which map segments of the output file back to their original lines of source. This allows browser debuggers to show the original source code, even if it&#39;s a language not actually supported by the JS interpreter in the browser.  The browser will show the &amp;quot;original source&amp;quot; in its individual files, and allows developers to debug that &amp;quot;original source&amp;quot; by setting breakpoints and viewing variable contents.&lt;/p&gt;

&lt;h2 id=&#34;development-environments-and-tools&#34;&gt;Development Environments and Tools&lt;/h2&gt;

&lt;h3 id=&#34;node-js&#34;&gt;Node.js&lt;/h3&gt;

&lt;p&gt;&lt;a href=&#34;https://nodejs.org&#34;&gt;Node.js&lt;/a&gt; is a runtime for executing JS outside of a browser environment.  It&#39;s equivalent to the JRE for Java, the .NET Framework SDK, or the Python runtime.  It consists of the V8 JS engine from Chrome repackaged for use as a standalone executable, along with a standard library of APIs for interacting with the file system, creating sockets and servers, and much more.&lt;/p&gt;

&lt;h3 id=&#34;npm&#34;&gt;NPM&lt;/h3&gt;

&lt;p&gt;&amp;quot;NPM&amp;quot; has three meanings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NPM is the publicly-hosted JS package registry that hosts third-party JS libraries and packages published by the community&lt;/li&gt;
&lt;li&gt;&lt;code&gt;npm&lt;/code&gt; is an open-source CLI client used for installing packages from that registry&lt;/li&gt;
&lt;li&gt;NPM is a company that runs the registry and develops the CLI client (recently bought by Microsoft)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Libraries and packages installed off of NPM are put into a &lt;code&gt;./node_modules&lt;/code&gt; folder.  So, &lt;code&gt;npm install redux&lt;/code&gt; downloads a published archive from the NPM registry servers, and extracts the contents into a new &lt;code&gt;./node_modules/redux&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;Yarn is an alternative package manager that installs the same packages from the same public NPM package registry.  It has the same core capabilities as the &lt;code&gt;npm&lt;/code&gt; tool, but provides some different configuration options.&lt;/p&gt;

&lt;h3 id=&#34;node-build-tools&#34;&gt;Node Build Tools&lt;/h3&gt;

&lt;p&gt;Since most JS build tools are written by JS developers for JS developers, the build tools themselves are typically written in JS.  This includes widely used tools like Babel, Webpack, ESLint, and many others.  So, to run them, you must have Node.js installed in your development environment.  (As described below, you do &lt;em&gt;not&lt;/em&gt; need Node.js installed on a server machine just to run your client code in a browser, unless you also have written your server application itself in JS.)&lt;/p&gt;

&lt;p&gt;There&#39;s been a recent trend of alternative JS build tools being written in Rust or Go, with a goal of making compilation and bundling much faster through use of native code and parallelism.  Most of these tools haven&#39;t hit mainstream usage yet, but the potential speedups are big enough that those tools are likely to pick up usage.&lt;/p&gt;

&lt;h3 id=&#34;dev-servers&#34;&gt;Dev Servers&lt;/h3&gt;

&lt;p&gt;Because the original source needs to be repeatedly re-compiled and re-bundled as a developer makes changes locally, the typical development process involves launching a &lt;em&gt;dev server&lt;/em&gt;, a separate process that detects edits to the original source files and rebuilds the client code with the changes.&lt;/p&gt;

&lt;p&gt;The dev server process typically acts as an HTTP proxy, and forwards requests for data and assets onwards to an actual application server.&lt;/p&gt;

&lt;p&gt;A typical example might look like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App server process listening on port 8080&lt;/li&gt;
&lt;li&gt;Dev server process listening on port 3000&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The developer would then browse to &lt;code&gt;http://localhost:3000&lt;/code&gt; to load the page.  The dev server on port 3000 receives the request, loads the HTML host page and bundled JS source from its memory, and returns it.  When the browser requests &lt;code&gt;http://localhost:3000/images/avatar.png&lt;/code&gt;, the dev server forwards that to the app server at &lt;code&gt;http://localhost:8080/images/avatar.png&lt;/code&gt; instead.  Similarly, a request for data by the browser to &lt;code&gt;GET http://localhost:3000/items&lt;/code&gt; would be forwarded to the app server at &lt;code&gt;http://localhost:8080/items&lt;/code&gt;, and the response passed back through the dev server to the browser.&lt;/p&gt;

&lt;p&gt;Webpack has a prebuilt dev server package available, and other tools such as Create-React-App often wrap around the Webpack dev server to provide additional configuration and capabilities.&lt;/p&gt;

&lt;h3 id=&#34;hot-module-reloading&#34;&gt;Hot Module Reloading&lt;/h3&gt;

&lt;p&gt;Normally, recompiling a web app requires completely reloading the page to see the changed code running.  This wipes out any state loaded into the app when the page is refreshed.&lt;/p&gt;

&lt;p&gt;Tools like Webpack offer a &amp;quot;hot module reloading&amp;quot; ability.  When a file is edited, the dev server recompiles with the changes, then pushes a notification to the client code in the browser.  The app code can then subscribe to &amp;quot;some file changed&amp;quot; notifications, re-import the new version of the code, and swap out the old code for the new code as the app is still running.&lt;/p&gt;

&lt;p&gt;Other tools like React&#39;s &amp;quot;Fast Refresh&amp;quot; mode can then leverage that reloading capability to swap specific parts of the app, such as replacing individual React components in real time.&lt;/p&gt;

&lt;h2 id=&#34;deployment&#34;&gt;Deployment&lt;/h2&gt;

&lt;h3 id=&#34;serving-build-output&#34;&gt;Serving Build Output&lt;/h3&gt;

&lt;p&gt;The output of a normal bundler build process is a folder full of static JS, HTML, CSS, and image files.  Here&#39;s the output structure of a typical React app:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/my-project/build
    - index.html
    /static
        /css
            - main.34928ada.chunk.css
            - 2.7110e618.chunk.css
        /js
            - 2.e5df1c81.chunk.js
            - 2.e5df1c81.chunk.js.map
            - main.caa84d88.chunk.js
            - main.caa84d88.chunk.js.map
            - runtime-main.d653cc00.js
            - runtime-main.d653cc00.js.map
        /media
            - image1.png
            - image2.jpg
            - fancy-font.woff2
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These are simple static files that can be served up by any web server.&lt;/p&gt;

&lt;p&gt;To deploy these files, they just need to be uploaded to an appropriate location on the machine that hosts the server application.  This is often done using a file transfer protocol such as SFTP.&lt;/p&gt;

&lt;h3 id=&#34;polyfills&#34;&gt;Polyfills&lt;/h3&gt;

&lt;p&gt;There are many browser APIs that do not exist in older browsers, but cannot be handled by backwards-compiling syntax.  This includes built-in functions, classes, and data types.  A couple examples of this are the &lt;code&gt;String.padStart()&lt;/code&gt; method and the &lt;code&gt;Map&lt;/code&gt; data structure.&lt;/p&gt;

&lt;p&gt;However, some of these can still be &lt;em&gt;polyfilled&lt;/em&gt; with developer-provided implementations.  Polyfills are extra code that is executed when an app is loaded, detects if a given feature exists at runtime in the current environment, and adds an artificial-but-equivalent implementation dynamically.  As an example, a polyfill for &lt;code&gt;String.padStart()&lt;/code&gt; might look something like:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;if (!String.prototype.padStart) {
  String.prototype.padStart = function padStart(targetLength,padString) {
    // actual logic here
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;code-splitting&#34;&gt;Code Splitting&lt;/h3&gt;

&lt;p&gt;Even with minification, JS bundles can get much too large (250K, 1MB, or worse).  This is often due to use of many third-party libraries for additional functionality.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code splitting&lt;/em&gt; allows bundlers to break very large bundles into smaller chunks.  The extra chunks are either added as additional &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags into the host HTML page, or dynamically downloaded as the app is running.&lt;/p&gt;

&lt;p&gt;Some chunks might contain only third-party code, so that the &amp;quot;vendor chunks&amp;quot; can be cached by the browser and only downloaded the first time a user visits a site.  Or, chunks might be common logic shared between multiple parts of an app, such as common utilities used by the main user-facing page and an admin page.&lt;/p&gt;

&lt;p&gt;Some chunks might be &amp;quot;lazy loaded&amp;quot; only when the user activates a certain feature.  For example, a rich text editor implementation might add an extra 500K to the bundle, but if it&#39;s only used in a specific modal dialog, the dialog code can dynamically import the text editor library.  The bundler then detects that dynamic import, splits the editor code into a separate chunk, and the chunk is only downloaded when the user opens that modal.&lt;/p&gt;

&lt;h2 id=&#34;further-resources&#34;&gt;Further Resources&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JS Module Formats&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/myshov/history-of-javascript/tree/master/4_evolution_of_js_modularity&#34;&gt;History of JavaScript: Evolution of JS Modularity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ui.dev/javascript-modules-iifes-commonjs-esmodules/&#34;&gt;JavaScript Modules: From IIFEs to CommonJS to ES6 Modules&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.sitepoint.com/understanding-es6-modules-via-their-history/&#34;&gt;Understanding ES6 Modules via Their History&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/&#34;&gt;ES Modules: A cartoon deep-dive&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Build Tools&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.swyx.io/jobs-of-js-build-tools/&#34;&gt;The Many Jobs of JS Build Tools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://tighten.co/blog/unpacking-webpack/&#34;&gt;Unpacking Webpack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.tezify.com/post/babel-and-webpack-fundamentals/&#34;&gt;Babel and Webpack Fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://overreacted.io/how-does-the-development-mode-work/&#34;&gt;How does the Development Mode Work?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deployment&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://create-react-app.dev/docs/deployment&#34;&gt;Create-React-App docs: Deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.newline.co/fullstack-react/30-days-of-react/day-27/&#34;&gt;Fullstack React: Deployment introduction&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>How Web Apps Work: HTTP and Servers</title>
      <link>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/</link>
      <pubDate>Fri, 06 Nov 2020 09:50:00 -0500</pubDate>
      
      <guid>https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-http-server/</guid>
      <description>&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Web development is a huge field with a vast array of concepts, terms, tools, and technologies. For people just getting started in web dev, this landscape is often bewildering - it&#39;s unclear what most of these pieces are, much less how they fit together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This series of posts provides an overview of fundamental web dev concepts and technologies, what these pieces are, why they&#39;re needed, and how they relate to each other&lt;/strong&gt;. It&#39;s not a completely exhaustive reference to everything in web development, nor is it a &amp;quot;how to build apps&amp;quot; guide. Instead, it&#39;s a map of the territory, &lt;strong&gt;intended to give you a sense of what the landscape looks like, and enough information that you can go research these terms and topics in more depth if needed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some of the descriptions will be more oriented towards modern client-side app development with JavaScript, but most of the topics are fundamental enough that they apply to server-centric applications as well.&lt;/p&gt;

&lt;p&gt;Other posts in this series cover additional topics, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-client-dev-deployment/&#34;&gt;Client Development and Deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-html-css/&#34;&gt;Browsers, HTML, and CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-javascript-dom/&#34;&gt;JavaScript and the DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://blog.isquaredsoftware.com/2020/11/how-web-apps-work-ajax-apis-data/&#34;&gt;AJAX, APIs, and Data Transfer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New terms will be marked in &lt;em&gt;italics&lt;/em&gt;. I&#39;ll link references for some of them, but encourage you to search for definitions yourself. Also, some of the descriptions will be simplified to avoid taking up too much space or dealing with edge cases.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web&#34;&gt;&lt;strong&gt;MDN web technologies documentation&lt;/strong&gt;&lt;/a&gt; is an excellent resource for reviewing many of the specific terms and concepts listed here in more detail.&lt;/p&gt;

&lt;h3 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#http&#34;&gt;HTTP&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#http-networking&#34;&gt;HTTP Networking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#http-requests-and-responses&#34;&gt;HTTP Requests and Responses&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#http-headers&#34;&gt;HTTP Headers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#http-methods&#34;&gt;HTTP Methods&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#get-requests&#34;&gt;&lt;code&gt;GET&lt;/code&gt; Requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#post-requests&#34;&gt;&lt;code&gt;POST&lt;/code&gt; Requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#put-requests&#34;&gt;&lt;code&gt;PUT&lt;/code&gt; Requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#patch-requests&#34;&gt;&lt;code&gt;PATCH&lt;/code&gt; Requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#delete-requests&#34;&gt;&lt;code&gt;DELETE&lt;/code&gt; Requests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#http-status-codes&#34;&gt;HTTP Status Codes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#cookies&#34;&gt;Cookies&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#servers&#34;&gt;Servers&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#basic-http-request-processing&#34;&gt;Basic HTTP Request Processing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#routing&#34;&gt;Routing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#static-files&#34;&gt;Static Files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#dynamic-server-application-logic&#34;&gt;Dynamic Server Application Logic&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#response-formats&#34;&gt;Response Formats&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#further-resources&#34;&gt;Further Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;http&#34;&gt;HTTP&lt;/h2&gt;

&lt;p&gt;Browsers effectively only speak one language to request information: the HyperText Transfer Protocol (HTTP). This means that a browser must talk to a server that also speaks HTTP and can respond to the browser&#39;s requests for information.&lt;/p&gt;

&lt;h3 id=&#34;http-networking&#34;&gt;HTTP Networking&lt;/h3&gt;

&lt;p&gt;All computer networking at the software level is based on an abstraction called a &lt;em&gt;socket&lt;/em&gt;. Sockets represent a specific open connection to another computer. A &lt;em&gt;server&lt;/em&gt; starts listening for incoming connections, and a &lt;em&gt;client&lt;/em&gt; asks to open a new connection. Connections are defined using numeric dot-separated &lt;em&gt;IP addresses&lt;/em&gt; like &lt;code&gt;192.168.0.255&lt;/code&gt;, and an additional numeric &lt;em&gt;port&lt;/em&gt; numbers like &lt;code&gt;8080&lt;/code&gt;. An individual IP address segment can be from &lt;code&gt;0-255&lt;/code&gt;, and port numbers range from &lt;code&gt;0-65535&lt;/code&gt;. Think of an IP address as a street address for an apartment building, and a port number as a specific room in that building. Any data can be sent over a socket - binary or text - it&#39;s all just bytes.&lt;/p&gt;

&lt;p&gt;Plain HTTP is an unencrypted protocol. HTTP Secure (HTTPS) is the same content, but encrypted before being sent.&lt;/p&gt;

&lt;p&gt;Standardized networking protocols use specific well-known port numbers. Plain HTTP defaults to port &lt;code&gt;80&lt;/code&gt;, and HTTPS defaults to port &lt;code&gt;443&lt;/code&gt;. So, an address of &lt;code&gt;http://192.168.0.255&lt;/code&gt; implies port 80, and &lt;code&gt;https://192.168.0.255&lt;/code&gt; implies port 443. Other ports are frequently used depending on project setup. For example, many web server applications listen on port 8080 or 3000 in a development environment, so in that case you would use an address like &lt;code&gt;http://192.168.0.255:3000&lt;/code&gt; as the destination for an HTTP connection.&lt;/p&gt;

&lt;p&gt;Since numeric URLs are hard to remember, and a site may be made up of many systems working together, the &lt;em&gt;Domain Name System&lt;/em&gt; (DNS) maps text name URLs like &lt;code&gt;www.google.com&lt;/code&gt; to a specific set of numeric IP addresses.&lt;/p&gt;

&lt;p&gt;A URL like &lt;code&gt;http://www.example.com:8080/some-page?id=42#intro&lt;/code&gt; can be split into multiple pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;protocol&lt;/em&gt;: &lt;code&gt;http://&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;subdomain&lt;/em&gt;: &lt;code&gt;www&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;domain name&lt;/em&gt;: &lt;code&gt;example.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;port&lt;/em&gt;: &lt;code&gt;8080&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;path&lt;/em&gt;: &lt;code&gt;some-page&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;query parameters&lt;/em&gt;: &lt;code&gt;?id=42&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;fragment&lt;/em&gt;: &lt;code&gt;#intro&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;http-requests-and-responses&#34;&gt;HTTP Requests and Responses&lt;/h3&gt;

&lt;p&gt;HTTP is a plain-text, &amp;quot;stateless&amp;quot;, request/response-based protocol. In other words:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A client application has to open a connection to the server and send a request using a text-based format&lt;/li&gt;
&lt;li&gt;The server then parses the request, runs code to process and handle the request appropriately, and sends back a text-based response. Once the response has been sent, it closes the open socket connection.&lt;/li&gt;
&lt;li&gt;Each request/response is an individual transaction between a client and a server, and by default there is no correlation between separate requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both requests and responses may also contain binary data, but the HTTP-related contents of the request and response are readable text instructions.&lt;/p&gt;

&lt;p&gt;A typical HTTP request looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;GET https://www.example.com/description.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) Chrome/16.0.912.75 Safari/535.7
Accept: text/html,application/xhtml+xml
Referer: http://www.google.com/url?&amp;amp;q=example
Accept-Language: en-US,en
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first line of the request is broken down into three pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The HTTP &lt;em&gt;method&lt;/em&gt; or &lt;em&gt;verb&lt;/em&gt;, such as &lt;code&gt;GET&lt;/code&gt; or &lt;code&gt;POST&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;path&lt;/em&gt; of the request&lt;/li&gt;
&lt;li&gt;The HTTP protocol version&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that, the request may contain additional &lt;em&gt;headers&lt;/em&gt;. Each header is a piece of metadata that the client can include so that the server better understands what kind of information is being requested.&lt;/p&gt;

&lt;p&gt;The request may also include a &lt;em&gt;body&lt;/em&gt; after the headers, with additional data.&lt;/p&gt;

&lt;p&gt;Responses follow the same structure:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Server: Apache/2.4
Date:   Sun, 01 Nov 2020 16:38:23 GMT
Content-Length: 17151

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Page Title Here&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  Content here
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first line contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The HTTP protocol version&lt;/li&gt;
&lt;li&gt;The HTTP &lt;em&gt;status code&lt;/em&gt;, in a numeric form&lt;/li&gt;
&lt;li&gt;The HTTP &lt;em&gt;status reason&lt;/em&gt;, in a text form&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is followed by additional &lt;em&gt;header&lt;/em&gt; lines containing metadata about the response, including the total byte size of the &lt;em&gt;body&lt;/em&gt;. Finally, the response includes the actual body contents.&lt;/p&gt;

&lt;h3 id=&#34;http-headers&#34;&gt;HTTP Headers&lt;/h3&gt;

&lt;p&gt;There are dozens of header fields that can be sent over HTTP, and both clients and servers can send additional arbitrary headers they&#39;ve defined. Some of the most common headers are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requests

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;User-Agent&lt;/code&gt;: a string describing the specific type and version of the client&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Cookie&lt;/code&gt;: a small piece of data previously attached by the server to help track this client&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Referer&lt;/code&gt;: URL of the previous page where a link was clicked&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Responses

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Length&lt;/code&gt;: size of the response in bytes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Location&lt;/code&gt;: redirect request to a new URL&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Set-Cookie&lt;/code&gt;: creates a new cookie value&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Both

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Content-Type&lt;/code&gt;: name of the format used in the request / response body&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;http-methods&#34;&gt;HTTP Methods&lt;/h3&gt;

&lt;p&gt;The HTTP protocol specifies several possible &lt;em&gt;methods&lt;/em&gt; or &lt;em&gt;verbs&lt;/em&gt;. Each HTTP method represents a different type of request intent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET&lt;/code&gt;: the client wants to retrieve information&lt;/li&gt;
&lt;li&gt;&lt;code&gt;POST&lt;/code&gt;: the client wants to create or update data on the server&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PUT&lt;/code&gt;: the client wants to update or replace data on the server&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DELETE&lt;/code&gt;: the client wants to delete some data on the server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each HTTP method has different variations in how the request is formatted, and when/why it should be used by a client. In addition, some types of requests can be treated as &amp;quot;idempotent&amp;quot; (can be done many times without causing additional changes).&lt;/p&gt;

&lt;h4 id=&#34;get-requests&#34;&gt;&lt;code&gt;GET&lt;/code&gt; Requests&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;GET&lt;/code&gt; requests are used to retrieve information from the server, based on a specific URL. &lt;code&gt;GET&lt;/code&gt; requests do not contain a request body. However, clients may include additional data as &lt;em&gt;query parameters&lt;/em&gt; options attached to the main URL. Query params start with a &lt;code&gt;?&lt;/code&gt;, and are formatted as &lt;code&gt;key=value&lt;/code&gt; pairs separated by ampersands: &lt;code&gt;/endpoint?a=1&amp;amp;b=stuff&lt;/code&gt;. Spaces and special characters in URLs may need to be &lt;em&gt;URL-encoded&lt;/em&gt;, where the original value is replaced by a &lt;code&gt;%&lt;/code&gt; and a number: &lt;code&gt;?a=Some Value&lt;/code&gt; might become &lt;code&gt;?a=Some%20Value&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;GET&lt;/code&gt; requests are only used for retrieving data, servers should not update data in response to a &lt;code&gt;GET&lt;/code&gt;. This means it should be safe to make the same &lt;code&gt;GET&lt;/code&gt; request multiple times without causing side effects.&lt;/p&gt;

&lt;h4 id=&#34;post-requests&#34;&gt;&lt;code&gt;POST&lt;/code&gt; Requests&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;POST&lt;/code&gt; requests are used to tell the server to update some data or process some information. &lt;code&gt;POST&lt;/code&gt;s typically include all relevant information in the body of the request, and rarely include query params.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;POST&lt;/code&gt; request bodies typically use a few common formats&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;quot;Form-encoded&amp;quot;: the same &lt;code&gt;key=value&lt;/code&gt; structure as query parameters, but in the body of a &lt;code&gt;POST&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Multi-part form data&amp;quot;: a delimited format that splits the body into sections&lt;/li&gt;
&lt;li&gt;&amp;quot;JSON&amp;quot;: a string representation of JavaScript data structures like objects and arrays&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&#34;put-requests&#34;&gt;&lt;code&gt;PUT&lt;/code&gt; Requests&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;PUT&lt;/code&gt; requests are very similar to &lt;code&gt;POST&lt;/code&gt; requests. Both involve sending data to the server with an intent to update. The intended difference is that a &lt;code&gt;PUT&lt;/code&gt; is intended to &lt;em&gt;create or replace&lt;/em&gt; a value, while a &lt;code&gt;POST&lt;/code&gt; is intended to &lt;em&gt;create or update&lt;/em&gt; a value. Conceptually, a &lt;code&gt;PUT&lt;/code&gt; &lt;em&gt;should&lt;/em&gt; be safe to do multiple times in a row, while a &lt;code&gt;POST&lt;/code&gt; is likely to cause something to happen separately for each request.&lt;/p&gt;

&lt;h4 id=&#34;patch-requests&#34;&gt;&lt;code&gt;PATCH&lt;/code&gt; Requests&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;PATCH&lt;/code&gt; requests are also similar to &lt;code&gt;PUT&lt;/code&gt; requests, but the intent is to send a &lt;em&gt;partial&lt;/em&gt; representation of an item, while &lt;code&gt;PUT&lt;/code&gt; is meant to send the &lt;em&gt;complete&lt;/em&gt; representation of an item.&lt;/p&gt;

&lt;h4 id=&#34;delete-requests&#34;&gt;&lt;code&gt;DELETE&lt;/code&gt; Requests&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;DELETE&lt;/code&gt; requests are used to ask a server to delete some data. Conceptually, it should be safe to make a &lt;code&gt;DELETE&lt;/code&gt; request multiple times - if a value is already gone, the server ought to ignore the request.&lt;/p&gt;

&lt;h3 id=&#34;http-status-codes&#34;&gt;HTTP Status Codes&lt;/h3&gt;

&lt;p&gt;All HTTP responses include a numeric status code, along with a text &amp;quot;reason&amp;quot; string that describes the status code value. Status codes are 3-digit numbers, grouped into these ranges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1xx&lt;/code&gt;: Informational&lt;/li&gt;
&lt;li&gt;&lt;code&gt;2xx&lt;/code&gt;: Successful&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3xx&lt;/code&gt;: Redirection&lt;/li&gt;
&lt;li&gt;&lt;code&gt;4xx&lt;/code&gt;: Client error&lt;/li&gt;
&lt;li&gt;&lt;code&gt;5xx&lt;/code&gt;: Server error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Common HTTP status codes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;200&lt;/code&gt; (&amp;quot;OK&amp;quot;): successful response&lt;/li&gt;
&lt;li&gt;&lt;code&gt;301&lt;/code&gt; (&amp;quot;Moved permanently&amp;quot;): the resource at this URL has been moved to a new URL&lt;/li&gt;
&lt;li&gt;&lt;code&gt;304&lt;/code&gt; (&amp;quot;Not Modified&amp;quot;): The value at this URL has not changed since last asked&lt;/li&gt;
&lt;li&gt;&lt;code&gt;400&lt;/code&gt; (&amp;quot;Bad Request&amp;quot;): the request was not formatted properly&lt;/li&gt;
&lt;li&gt;&lt;code&gt;401&lt;/code&gt; (&amp;quot;Not Authorized&amp;quot;): not authenticated to view this&lt;/li&gt;
&lt;li&gt;&lt;code&gt;403&lt;/code&gt; (&amp;quot;Forbidden&amp;quot;): not allowed to view this&lt;/li&gt;
&lt;li&gt;&lt;code&gt;404&lt;/code&gt; (&amp;quot;Not Found&amp;quot;): server does not recognize this URL&lt;/li&gt;
&lt;li&gt;&lt;code&gt;500&lt;/code&gt; (&amp;quot;Internal Server Error&amp;quot;): something went wrong on the server while handling this&lt;/li&gt;
&lt;li&gt;&lt;code&gt;503&lt;/code&gt; (&amp;quot;Service Unavailable&amp;quot;): a portion of the server is down and cannot respond&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;cookies&#34;&gt;Cookies&lt;/h3&gt;

&lt;p&gt;HTTP is inherently &amp;quot;stateless&amp;quot; by default, but servers normally want some way to correlate a specific client&#39;s identity between multiple requests. For example, if I log into a forum site, the server should remember that I&#39;m logged in as I browse through different pages.&lt;/p&gt;

&lt;p&gt;The HTTP spec allows servers to include &lt;code&gt;Set-Cookie&lt;/code&gt; headers in responses with specific keys and values:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;HTTP/2.0 200 OK
Content-Type: text/html
Set-Cookie: yummy_cookie=choco
Set-Cookie: tasty_cookie=strawberry
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Whenever a client makes future requests to that server, the cookie values will be automatically included in the request:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;GET /sample_page.html HTTP/2.0
Host: www.example.org
Cookie: yummy_cookie=choco; tasty_cookie=strawberry
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Typically, a server will set a &amp;quot;session cookie&amp;quot; that contains some unique ID value, and map that unique ID internally to additional data (such as &amp;quot;session ID 12345 is actually user &lt;code&gt;mark&lt;/code&gt;&amp;quot;). That way, each time a request is made, the server can look up the additional data needed to handle that specific user (&amp;quot;Request is for &lt;code&gt;/messages&lt;/code&gt;, and the session data says the user is &lt;code&gt;mark&lt;/code&gt; - query the database for all messages sent to user &lt;code&gt;mark&lt;/code&gt;&amp;quot;).&lt;/p&gt;

&lt;h2 id=&#34;servers&#34;&gt;Servers&lt;/h2&gt;

&lt;p&gt;The word &amp;quot;server&amp;quot; has multiple related meanings depending on the context:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The application that opened up a socket to listen for incoming requests&lt;/li&gt;
&lt;li&gt;An application that is specifically able to handle HTTP requests and send back responses&lt;/li&gt;
&lt;li&gt;The physical or virtual machine that is running that server application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, we&#39;re going to focus on the &amp;quot;HTTP request handling application&amp;quot; meaning.&lt;/p&gt;

&lt;h3 id=&#34;basic-http-request-processing&#34;&gt;Basic HTTP Request Processing&lt;/h3&gt;

&lt;p&gt;Every HTTP server application starts handling a request by accepting an incoming socket connection, and parsing the request contents into some internal data structure. The server then inspects the HTTP request path and the method to determine the intent of the request.&lt;/p&gt;

&lt;p&gt;Depending on how the server has been written and configured, it will then handle the request by doing some combination of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reading files from disk&lt;/li&gt;
&lt;li&gt;Connecting to a database and loading / updating data&lt;/li&gt;
&lt;li&gt;Updating session tracking information internally&lt;/li&gt;
&lt;li&gt;Running developer-specified logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ultimately, the server application will fill out an HTTP response message based on all of the processing, write it to the socket, and close the connection.&lt;/p&gt;

&lt;h3 id=&#34;routing&#34;&gt;Routing&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Routing&lt;/em&gt; refers to determining what code to run based on a request URL. Servers normally use a combination of the HTTP request method and the request URL path to determine what code should handle a request. For example, &lt;code&gt;GET /users&lt;/code&gt; might be handled by one specific function, &lt;code&gt;POST /users&lt;/code&gt; by a second function, and &lt;code&gt;GET /images/header.png&lt;/code&gt; by another function.&lt;/p&gt;

&lt;p&gt;Servers typically use a convention that if &lt;code&gt;/some-folder/index.html&lt;/code&gt; exists, it will be used as the response contents for a request to &lt;code&gt;GET /some-folder/&lt;/code&gt;. This pattern has carried over into many other areas as well. For example, a server written using the PHP language might use &lt;code&gt;/some-folder/index.php&lt;/code&gt; to handle requests, and the Node.js CommonJS module format will handle an attempt to load &lt;code&gt;require(&#39;some-folder&#39;)&lt;/code&gt; by opening &lt;code&gt;some-folder/index.js&lt;/code&gt; if it exists.&lt;/p&gt;

&lt;h3 id=&#34;static-files&#34;&gt;Static Files&lt;/h3&gt;

&lt;p&gt;Many HTTP requests are asking for the server to return a copy of a specific file, such as &lt;code&gt;GET /images/header.png&lt;/code&gt; or &lt;code&gt;GET /app/index.html&lt;/code&gt;. A server will usually handle these by mapping URLs to a specific set of folders on disk, and checking to see if a file by that name exists in the specific folder path. If it does, the server will immediately handle the request by reading the entire file from disk and returning its contents as the body of the response.&lt;/p&gt;

&lt;p&gt;Since these files on disk typically do not change often, they are known as &lt;em&gt;static files&lt;/em&gt;. Serving static files is a baseline capability that all HTTP server applications can do, and most web server frameworks provide a built-in mechanism for automatically serving files from a designated folder. There are many sites and tools which &lt;em&gt;only&lt;/em&gt; host and serve static files - a user just needs to upload their files, and the site is already configured to serve them automatically.&lt;/p&gt;

&lt;h3 id=&#34;dynamic-server-application-logic&#34;&gt;Dynamic Server Application Logic&lt;/h3&gt;

&lt;p&gt;However, servers also need to respond to incoming requests by running additional logic written by a developer. The exact syntax and techniques used to define server logic vary widely across languages and server application frameworks, but they all share some common aspects. A typical web application server framework will allow the developer to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Specify which HTTP method is being handled&lt;/li&gt;
&lt;li&gt;Specify what URL routes are being handled&lt;/li&gt;
&lt;li&gt;Read an object representing the parsed HTTP request, which will contain fields with all the headers, other metadata, and body contents&lt;/li&gt;
&lt;li&gt;Interact with an object representing the in-progress HTTP response, which will contain fields and methods to help generate the final response contents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many web app frameworks also implement some form of &lt;em&gt;middleware&lt;/em&gt;, which are individual chunks of logic that are combined together. Each individual middleware typically has a specific purpose, such as adding session info to the request based on a cookie. The combined middleware then form a pipeline of preprocessing steps that are executed on every incoming request before the request is handled by the specific application logic.&lt;/p&gt;

&lt;p&gt;The request handling code may then use whatever logic it wants to dynamically generate a response. The handler logic might:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the URL and HTTP method&lt;/li&gt;
&lt;li&gt;Check cookies for a session ID and look up a user&#39;s details internally&lt;/li&gt;
&lt;li&gt;Read query parameters&lt;/li&gt;
&lt;li&gt;Extract data from a request body&lt;/li&gt;
&lt;li&gt;Connect to a database to retrieve information&lt;/li&gt;
&lt;li&gt;Run some calculations&lt;/li&gt;
&lt;li&gt;Update the database based on the calculations or the request contents&lt;/li&gt;
&lt;li&gt;Construct an HTML document or a JSON data structure&lt;/li&gt;
&lt;li&gt;Send that content back as the response body&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here&#39;s a (fictional!) typical example using the Express HTTP library for the Node.js runtime:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;language-js&#34;&gt;const express = require(&#39;express&#39;);
const session = require(&#39;express-session&#39;);

const db = require(&#39;./dbConnection&#39;);

const app = express();

// Add middleware to populate req.session
app.use(
  session({
    secret: &#39;keyboard cat&#39;,
  })
);

// Add middleware for processing incoming request contents
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Add middleware to serve static files
// URLs starting with &#39;/static&#39; will be mapped to files in the &#39;./public&#39; folder
app.use(&#39;/static&#39;, express.static(&#39;public&#39;));

// Define a request handler function that receives objects for request and response
function countViews(req, res) {
  // Build up an HTML body string as we go through
  let body = &#39;&#39;;
  // Session middleware added data to the request object
  if (req.session.views) {
    ++req.session.views;
  } else {
    req.session.views = 1;
    body += &#39;&amp;lt;p&amp;gt;First time visiting? view this page in several browsers :)&amp;lt;/p&amp;gt;&#39;;
  }

  // Send back HTML content in the response
  res.send(
    body + &#39;&amp;lt;p&amp;gt;viewed &amp;lt;strong&amp;gt;&#39; + req.session.views + &#39;&amp;lt;/strong&amp;gt; times.&amp;lt;/p&amp;gt;&#39;
  );
}

async function addBook(req, res) {
  // JSON body contents were processed into plain JS objects
  const { author, title } = request.body;

  // Send update request to DB and wait for it to complete
  await db.query(&#39;INSERT INTO books (author, title) VALUES ($1, $2)&#39;, [
    author,
    title,
  ]);

  // Send a specific HTTP status message and JSON-formatted response
  res.status(201).json({ status: &#39;success&#39;, message: &#39;Book added.&#39; });
}

// Define a handler for GET requests to the &#39;/&#39; URL path.
app.get(&#39;/&#39;, countViews);

// Define a handler for POST requests to the &#39;/books&#39; URL path
app.post(&#39;/books&#39;, addBook);

if (!module.parent) {
  // Use port 3000 to listen for incoming request socket connections
  app.listen(3000);
  console.log(&#39;Express started on port 3000&#39;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The exact syntax for each of these steps varies based on programming language and web framework, but all frameworks share these same basic concepts and capabilities in some form.&lt;/p&gt;

&lt;h3 id=&#34;response-formats&#34;&gt;Response Formats&lt;/h3&gt;

&lt;p&gt;Servers can send back any data they want in a response, but most responses are sent back with one of a few common formats:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML: the standard markup language that describes the structure and content of a web page&lt;/li&gt;
&lt;li&gt;CSS: the standard styling language used to define the appearance of a web page&lt;/li&gt;
&lt;li&gt;JSON: a text-based data format based on the syntax for JavaScript objects, arrays, and primitive values&lt;/li&gt;
&lt;li&gt;XML: a customizable text-based data format based on nested tags, similar to HTML&lt;/li&gt;
&lt;li&gt;Actual static files (images, JavaScript files, etc)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For data, JSON has become the de-facto standard data transfer format.&lt;/p&gt;

&lt;h2 id=&#34;further-resources&#34;&gt;Further Resources&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;HTTP&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP&#34;&gt;MDN: An Overview of HTTP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://doepud.co.uk/blog/anatomy-of-a-url&#34;&gt;Anatomy of a URL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.jmarshall.com/easy/http/&#34;&gt;HTTP Made Really Easy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://launchschool.com/books/http/read/introduction&#34;&gt;Introductory HTTP Book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://odetocode.com/Articles/741.aspx&#34;&gt;A Software Developer&#39;s Guide to HTTP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://webaim.org/blog/user-agent-string-history/&#34;&gt;History of the browser user-agent string&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request&#34;&gt;Stack Overflow: How are parameters sent in an HTTP POST request&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.cloudflare.com/learning/dns/what-is-dns/&#34;&gt;What is DNS?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;How the Web Works&amp;quot; series:&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.preethikasireddy.com/post/how-the-web-works-a-primer-for-newcomers-to-web-development-or-anyone-really&#34;&gt;Part 1: A Primer for Newcomers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.preethikasireddy.com/post/how-the-web-works-part-ii-client-server-model-the-structure-of-a-web-application&#34;&gt;Part 2: Client-Server Model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.preethikasireddy.com/post/how-the-web-works-part-iii-http-rest&#34;&gt;Part 3: HTTP and REST&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Other Overviews&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web&#34;&gt;MDN web technologies documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/alex/what-happens-when&#34;&gt;What happens when you type &#39;google.com&#39; and press Enter?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.robinwieruch.de/web-applications&#34;&gt;Web Applications 101&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.taniarascia.com/node-express-postgresql-heroku/&#34;&gt;Build a Node, Express, and PostgreSQL REST API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
  </channel>
</rss>